<daurnimator>
ryuukk_: as I mentioned above, Vectors are built in.
<daurnimator>
but yes; for e.g. matrices, you do need to write thatr
<ryuukk_>
Matrices is same problem
<kandinski>
ryuukk_: maybe you can contribute an std.meta.Matrix type and then the problem will be over
<daurnimator>
but as it says in the issue I linked earlier: it looks much better on multiple lines: `const c = Matrix.add(a, b); const d = Matrix.div(c, 4);` etc.
<daurnimator>
now; imagine that it was something like bignums: you need to handle allocations in there
<ryuukk_>
it doesn't, that's not how people write formulaes
<daurnimator>
and we accept that trade off.
<ryuukk_>
trade off? i don't see where the trade off is
<daurnimator>
"operator overloading makes generic code harder to read from a control flow perspective" vs "operator overloading makes math code easier to read from a math perspective"
<ryuukk_>
math, that's all computers are about
<pjz>
What about an expression compiler instead?
<ryuukk_>
i don't know what that is
<ryuukk_>
all i want is do math sanely
<pjz>
some math mini-lang that so you could write expressions how you want, and they'd get compiled into good code.
<pjz>
kind of like how formatting is done
<ryuukk_>
that sounds like too much for doing a + b
<pjz>
but it's not just a+b is it?
<ryuukk_>
if it's not built in into the language, it makes it just not viable at all
<ryuukk_>
it is, it is just operator overloading
<ryuukk_>
telling compile i can do a + b on my structs, just like he does for i32
<pjz>
hmm
<pjz>
you kind of have a point. I grok + for ints - math there is easy. but extending it to floats seems 'special'
<pjz>
and if to floats, why not to ... ?
<pjz>
Honestly, a + b might not be clear if it's int + float
<kandinski>
which one is coercd to which?
<kandinski>
and why?
<pjz>
or does it type-error/
<kandinski>
if you're allowed overloading, it might launch a missile
<pjz>
it's already allowed... float + int, no?
<pjz>
I mean, + works for both int and float
<pjz>
so it's already overloaded.
<kandinski>
what I mean is, if we allow overloading by users
waleee-cl has quit [Quit: Connection closed for inactivity]
<daurnimator>
pjz: no.error: incompatible types: 'u32' and 'f32'
<pjz>
daurnimator: ah! thanks! I was just opening another window to test that :)
<pjz>
well, as long as zig admits that floats are somehow special in that they get operator overloading, sure.
<daurnimator>
pjz: f32 and comptime_int is allowed though.
<daurnimator>
so you have to be a little careful when testing it :)
<pjz>
ohh, interesting.
Ondingen has quit [Remote host closed the connection]
<pjz>
so here's a stupid idea: have zig fmt write a comment at the end of lines with overloaded operators.
<pjz>
if the point is readability, call it out.
<kandinski>
pjz: but it's not overloading, it's coercion
<pjz>
I thought ryuukk wanted overlaoding?
<kandinski>
I mean what happens when you add a float and a comptime int is not so much overloading as coercion
<kandinski>
the + sign does what it does for floats
<kandinski>
it's just that the compiler knows to upgrade the comptime int to a float
<kandinski>
and then uses the same + at runtime
<kandinski>
without overloading it
<pjz>
oh, right. Gotcha.
<oats>
ah, the joys of figuring out how to make my homebrew circe notifications hook *not* notify me on "floats" :P
<kandinski>
floots from now on
<daurnimator>
f32-and-friends
<oats>
32 bit flooting point numbers
<pjz>
but the point is that + is overloaded since it works for ints and floots.
<kandinski>
pjz: I would dispute this
<daurnimator>
pjz: overload means to give *extra* meaning than what they mean by default in the language
<daurnimator>
pjz: what + does is *not* customisable in zig.
<kandinski>
but I"llagree that ** seems overloaded since it means both "raise to the power" for numerics and "repeat pattern" for string literals.
<pjz>
right. A stricter version of 'overload' is 'works with multiple types'
<pjz>
which is what I was thinking of
<pjz>
mostly from a method-overload stance
<kandinski>
pjz, technically you're right, but emotionally these feel all like "numerics"
<pjz>
but so do complex numbers and vectors.
<kandinski>
ah also you have a point
<pjz>
what about allowing explicit overloading?
<daurnimator>
zig does not have complex numbers
<kandinski>
my solution would be to add the standard mathematical types (complex numbers, matrices) to the std library
<pjz>
so, like _+_ would be an overloaded +
<pjz>
or something - notation/syntax TBD
<kandinski>
I mean, I'm *not*_requesting_ this, to be clear
<daurnimator>
pjz: see the issue(s) I linked earlier. they have such proposals in them.
<pjz>
ah? kk, will look.
<kandinski>
but if someone saw lack of matrix_a + matrix_b syntax as a real problem, I think that's the correct solution for them, in zig
ur5us has quit [Ping timeout: 260 seconds]
<pjz>
hmm, k. method chaining can make it look decent, but still not as fluent as operators.
<pjz>
but I heartly agree with the lack of magic.
<pjz>
er, the importance of explicitness, I mean.
marnix has joined #zig
endragor has quit [Ping timeout: 265 seconds]
cole-h has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
ask6155 has joined #zig
haliucinas has quit [Remote host closed the connection]
ask6155 has left #zig [#zig]
haliucinas has joined #zig
ttb has quit [Ping timeout: 245 seconds]
skuzzymiglet has joined #zig
osa1 has joined #zig
[RMS] has quit [Ping timeout: 260 seconds]
[RMS] has joined #zig
skuzzymiglet has quit [Ping timeout: 260 seconds]
earnestly has joined #zig
user0 has joined #zig
decentpenguin has quit [Read error: Connection reset by peer]
decentpenguin has joined #zig
osa1 has quit [Read error: Connection reset by peer]
osa1 has joined #zig
omglasers2 has joined #zig
shurane has joined #zig
osa1 has quit [Read error: Connection reset by peer]
osa1 has joined #zig
ur5us has joined #zig
oxymoron93 has joined #zig
cole-h has quit [Quit: Goodbye]
<kandinski>
this is a minimal test case where I try to import pcre2 but fail because I can't set the value of PCRE2_CODE_UNIT_WIDTH: https://termbin.com/aotkm
AceNovo has joined #zig
AceNovo has quit [Client Quit]
cole-h has joined #zig
AceNovo has joined #zig
<kandinski>
can anybody suggest a way to pass the #define up to the c library?
cole-h has quit [Ping timeout: 256 seconds]
AceNovo has quit [Quit: Konversation terminated!]
AceNovo has joined #zig
<ifreund_>
@cDefine()
AceNovo has quit [Client Quit]
AceNovo has joined #zig
<kandinski>
ifreund_: thanks
<kandinski>
since I'm interacting with C libraries, I'm using 0-sentinel terminated u8 arrays a bit. Can anyone point me to some code I could crib from for best practices?
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
AceNovo has quit [Ping timeout: 240 seconds]
ask6155 has joined #zig
ask6155 has left #zig [#zig]
omglasers2 has quit [Ping timeout: 272 seconds]
m4r35n357 has joined #zig
radgeRayden has quit [Ping timeout: 272 seconds]
msingle has joined #zig
jorangreef has joined #zig
<jorangreef>
Hey everyone! What's the safest way to cast a []u8 slice to a slice of packed structs?
<jorangreef>
i.e. something like: @ptrCast([*]PackedStruct, @alignCast(@alignOf(PackedStruct), u8_slice))[0..count];
kristoff_it1 has joined #zig
Kingsquee has quit []
msingle has quit [Ping timeout: 240 seconds]
marnix has quit [Ping timeout: 264 seconds]
marnix has joined #zig
xackus has joined #zig
<daurnimator>
jorangreef: mem.bytesAsSlice ?
<jorangreef>
(y) Thanks, the source of that looks perfect. Is there any difference between the snippet above and bytesAsSlice, e.g. how they do alignment, assuming the divExact check is done for both?
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
xackus has quit [Ping timeout: 272 seconds]
omglasers2 has joined #zig
<Piraty>
is `zig cc` capable of compiling c++ ?
<pixelherodev>
`zig c++` I think?
<Piraty>
ah
<Piraty>
--help doesn't mention
<Piraty>
yet it seems to at leat try
<Piraty>
yeah works
<Piraty>
cross target fails to find a system header though...
wilsonk has quit [Remote host closed the connection]
<earnestly>
You'll have to tell zig where to look for them iiuc
wilsonk has joined #zig
ask6155 has joined #zig
<Piraty>
got it
jorangreef has quit [Remote host closed the connection]
ask6155 has left #zig [#zig]
<ifreund>
Piraty: passing -lc should be all you need
<ifreund>
or -lwhatever
<earnestly>
-lstdc++? heh
<ifreund>
oh yeah this is C++ :P
<ifreund>
-std=c99 is what I pass to zig cc actually
msingle has joined #zig
ask6155 has joined #zig
donniewest has joined #zig
oxymoron93 has quit [Quit: Connection closed]
FireFox317 has joined #zig
ask6155 has left #zig [#zig]
<FireFox317>
andrewrk, i created #6746 regarding the infinite loops when doing dirname. I'm not sure if this is what you had in mind, but i know that this issue was still on your todo list before 0.7.0.
xackus has joined #zig
hnOsmium0001 has joined #zig
skuzzymiglet has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
m4r35n357 has quit [Quit: Ex-Chat]
haliucinas has quit [Read error: Connection reset by peer]
haliucinas has joined #zig
earnestly has quit [Ping timeout: 260 seconds]
hardy7cc has joined #zig
ask6155 has joined #zig
hardy7cc has quit [Remote host closed the connection]
<ikskuh>
can someone explain why zig always sets FILE_SHARE_DELETE on windows when opening a file?!
<ikskuh>

<ikskuh>
Nachricht an #zig
<ikskuh>
andrewrk, daurnimator?
notpiika has joined #zig
FireFox317 has quit [Quit: Leaving]
ask6155 has left #zig [#zig]
tane has joined #zig
earnestly has joined #zig
cole-h has joined #zig
waleee-cl has joined #zig
zippoh has quit [Remote host closed the connection]
skuzzymiglet has quit [Ping timeout: 272 seconds]
demizer has joined #zig
zippoh has joined #zig
user0 has quit [Remote host closed the connection]
Akuli has joined #zig
ryuukk__ has joined #zig
ryuukk_ has quit [Ping timeout: 260 seconds]
ryuukk_ has joined #zig
ryuukk__ has quit [Ping timeout: 260 seconds]
mixi has quit [Quit: quit]
mixi has joined #zig
<pixelherodev>
ikskuh: what does that flag do?
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
<ikskuh>
it allows me deleting this file but not deleting it
<pixelherodev>
...?
frett27 has joined #zig
<ikskuh>
windows things:
<ikskuh>
opening a file locks it against deletion by default
<ikskuh>
zig prevents this behaviour by-default
AceNovo has joined #zig
skuzzymiglet has joined #zig
radgeRayden has joined #zig
Stephanie has joined #zig
Stephie has quit [Ping timeout: 265 seconds]
wootehfoot has joined #zig
<justin_smith>
ikskuh: one hunch to check - this means that the behavior would match the default posix behavior, which means fewer corner cases to keep track of
<justin_smith>
that's just a blatant guess though
<ikskuh>
yeah that's my guess as well
fgenesis has quit [Ping timeout: 256 seconds]
AceNovo has quit [Remote host closed the connection]
ur5us has joined #zig
ur5us has quit [Ping timeout: 244 seconds]
donniewest1 has joined #zig
donniewest has quit [Ping timeout: 240 seconds]
donniewest2 has joined #zig
donniewest1 has quit [Ping timeout: 256 seconds]
marijnfs has joined #zig
marijnfs has quit [Ping timeout: 246 seconds]
marnix has quit [Ping timeout: 265 seconds]
ur5us has joined #zig
frett27 has quit [Ping timeout: 256 seconds]
osa1 has quit [Ping timeout: 272 seconds]
wootehfoot has quit [Ping timeout: 272 seconds]
tane has quit [Quit: Leaving]
wootehfoot has joined #zig
skuzzymiglet has quit [Ping timeout: 260 seconds]
marijnfs has joined #zig
<marijnfs>
I have a zig conundrum
<marijnfs>
I want to have an arraylist of callbacks, but the callbacks might get different inputs. So i'm not sure how to design the callback
<marijnfs>
I was trying to have a standard struct that would be a member of other structs, and get the pointer with getParentPtr
<ikskuh>
what about union(enum) { cb_a: fn() void, cb_b: fn(i32) void, … } ?
<kandinski>
can anybody point me to zig code wrapping a heap-using C library so I can crib on best practices? I'm new to both Zig and C, know a lot of the theory but this is my first time managing memory by hand.
<ifreund>
mostly just use std.heap.c_allocator aliased to util.gpa plus a few arenas on top of that in places
<kandinski>
hmm
<kandinski>
for now I'm not writing a library for others to use, just a one-file wrapper with barely enough functionality for my own use
<kandinski>
but it's a learning project and I want to learn "the right way"
<kandinski>
I'm implementing python's `re.compile(): Pattern` and `Pattern.findall()` on top of pcre2-8
<kandinski>
so I'll have something nice to use for my actual-program-that-needs-regexps
<ifreund>
well, unless the C code is nice enough to accept a custom allocator as a parameter you're pretty much stuck with using the C allocator as well
<kandinski>
that's what I've figured out. Yes, it's a good library, but it's any colour you want as long as it's the C heap
donniewest2 has quit [Quit: WeeChat 2.9]
radgeRayden has quit [Remote host closed the connection]
Akuli has quit [Quit: Leaving]
wootehfoot has quit [Ping timeout: 258 seconds]
ryuukk_ has quit [Read error: Connection reset by peer]
ryuukk_ has joined #zig
msingle has quit [Ping timeout: 240 seconds]
omglasers2 has quit [Read error: Connection reset by peer]
<ryuukk_>
Structs, unions, and arrays can sometimes be more efficiently passed as a reference, since a copy could be arbitrarily expensive depending on the size. When these types are passed as parameters, Zig may choose to copy and pass by value, or pass by reference, whichever way Zig decides will be faster. This is made possible, in part, by the fact that parameters are immutable.
<ryuukk_>
what the size compiler decide it's gonna be value or reference?
<ryuukk_>
: Vec2 is enough to let compiler pass by reference when it's good?
<marijnfs>
ryuukk_: &Vec2{.x=1, .y=2} works with the const*
ur5us has joined #zig
<ryuukk_>
marijnfs: thanks
<ryuukk_>
in perfect world &.{} would be perfect, but looks like it's not a thing
marijnfs has quit [Ping timeout: 258 seconds]
marijnfs has joined #zig
<marijnfs>
ryuukk_: &Vec2{.x=1, .y=2} works with the const*