ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<daurnimator> andrewrk: hey just watching your video (via HN)
<daurnimator> andrewrk: should mention Lua as a lang that you can suprisingly write "perfect code"
<daurnimator> andrewrk: also I didn't get my reply in scrollback overnight :)
davr0s has joined #zig
porky11 has quit [Quit: Leaving]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
wilsonk has quit []
<hryx> daurnimator: I must agree about the Lua comment :>
<hryx> I'd love some feedback from people here on a proposal. I don't want to put this up on GitHub if it's a dupe, or captured better somewhere else. Or if it contains lies/errors.
<hryx> Lemme know what you think!
<hryx> (title is "RFC: Make function definitions expressions")
wilsonk has joined #zig
<shachaf> Hmm, I started writing about what I want in an error-handling system a little while ago and came up with something pretty close to what Zig has: http://slbkbs.org/tmp/5-error-handling.txt
<shachaf> Actually it looks like Zig has a lot of language features I've been wanting and trying to figure out, like named-break-with-value
<shachaf> How does the |x| { ... } syntax work? Is it a standalone thing in some way or syntactically a part of for/catch/etc.?
<hryx> shachaf: That syntax is specific to constructs which a) "unwrap" a value which can be null/error, or b) provide reference during iteration, switch, etc.
<hryx> far as I know it means nothing on its own
<shachaf> OK, that's what I figured.
<hryx> Also shachaf, that's quite a thoughtful braindump on error handling. how do you like Zig's so far?
<shachaf> I've been wondering about a general meaning for "block argument that can early-exit" that can be worked out at compile-time and isn't macros or something complicated like delimited continuations. But I think having these things be user-defined might be counter to the Zig philosophy.
<shachaf> I haven't actually used Zig yet, though I heard of it before. I'll have to look at it a bit more, though, it looks like it has some form of a bunch of things I've wanted.
steveno has joined #zig
steveno has quit [Quit: Leaving]
steveno has joined #zig
<hryx> Also shachaf, that's quite a thoughtful braindump on error handling. how do you like Zig's so far?
<hryx> oops, sorry. Accidentally hit up ._.
<jfondren> glibc's getrusage() headers are awful: https://gist.github.com/jrfondren/1d98e9dcc056184f1317a1ac47e59673
<jfondren> all that and it's just an array of ints, really.
steveno has quit [Quit: Leaving]
<hryx> jfondren: can you explain the @"" in that link? Are those some kind of anonymous struct members or something?
<shachaf> A lot of things in glibc seem pretty bad. Some functions are just way worse than the system calls they're wrapping.
<shachaf> It looks like Zig binaries on Linux aren't dynamically linked at all? How do they handle things like DNS?
<jfondren> the @"" doesn't compile. So I thought about submitting that as a bug. But the other file there is produced by gcc itself, and it's also completely useless.
wootehfoot has quit [Read error: Connection reset by peer]
<jfondren> zig produces dynamically-linked binaries with --library c
<jfondren> speaking of |x| { error handling }, I just rewrote that gist to use those. that's quite a bit nicer.
<shachaf> OK, so if you want to use system libraries you have to link libc presumably.
<shachaf> I guess DNS is less of an issue than things like OpenGL.
<jfondren> if you want to use system libraries you have to link with them, sure. But there's a lot of functionality in syscalls that zig can invoke directly, and the functionality in the system libraries can be reimplemented without the libraries. For DNS, there's already stuff like FireDNS, libdns, etc., that you might prefer to gethostbyname
<jfondren> I'd say, --library is an option. (literally.)
<shachaf> Yes, the system DNS library isn't great anyway, and I guess parsing resolv.conf yourself is the best you can do.
<shachaf> But if you want e.g. libGL there's not much you can do (?).
<MajorLag> hryx, overall I think it's a solid proposal. The idea has been brought up a few times but hasn't really been anyone's priority. Personally, I'm in favor of it because it is more consistent with the rest of the language and it means I can stop wrapping comptime-generated functions in structs. Honestly not sure which syntax for `extern` makes more sense.
<hryx> Thank you MajorLag. If it's a worthwhile consideration I'll post it. I've been looking for some way to contribute to zig with my limited experience -- this is something I'd be down to tackle, though I have no idea how much work is involved yet.
<hryx> jfondren: Hope you don't mind, I made a revision using `orelse` to reduce the indentation. also removed stdio.h https://gist.github.com/hryx/108570362b9ce9897f54f6e2ee542bb6
<shachaf> On closures: I recently found out that D supports closures relative to a stack frame, which are only valid inside the scope they're defined in.
<hryx> shachaf: have you looked at the Tetris proof of concept? (By Andrew, author of zig) It links against GLFW and libpng: https://github.com/andrewrk/tetris
<shachaf> I'm not sure whether it's a good idea in general but it would work for some of the examples in #1048 with no extra copying.
<shachaf> Nope, haven't looked.
<daurnimator> shachaf: I assume by asking about dns you're really asking about nss libs your system may expect?
<shachaf> daurnimator: Yes.
<shachaf> Recently I was trying to figure out what the real ABI that you need to/can assume when writing static Linux binaries is.
<daurnimator> shachaf: I assume the best answer would be the same as it is in musl: the nss shared library mode is a terrible idea: use of the nscd socket is the least-bad way to get it
<shachaf> The answer is something like, the Linux system call ABI, which is nice, and then a bunch of things like parsing reasonably stable formats like /etc/resolv.conf and /etc/passwd yourself.
<daurnimator> shachaf: also lots of /proc and /sys....
<daurnimator> shachaf: and then you have what the system dynamic linker expects/understands
<shachaf> Right. But at least that's in ther ketnel and it's pretty well-specified.
<shachaf> And then when you get to things that you just have to dynamically link, like OpenGL, it more or less pulls in the system libc anyway.
<daurnimator> shachaf: and then you have some other interesting things like set_robust_list, which should only ever be called *once* in a thread. usually glibc is the thing to do it, but if you don't have glibc..... ?
<shachaf> Well, if you're writing your own runtime presumably you're taking care of that.
<daurnimator> shachaf: but what about when you then link against something else that expects glibc's management functions for it
<daurnimator> you end up having to emulate misc glibc apis...
<shachaf> Right.
<shachaf> If it's statically linked then at least you know what the surface you have to emulate is.
<daurnimator> shachaf: if what is statically linked?
<daurnimator> shachaf: what if you're using zig to create a shared library though
<shachaf> The something thing you link against.
<shachaf> It's all just a mess.
return0e has quit [Read error: Connection reset by peer]
nschuc has joined #zig
nschuc has left #zig [#zig]
return0e has joined #zig
oats has joined #zig
<oats> howdy, I'm getting familiar with some zig by following along with the x86 kernel live-coding video, which I'm finding very fun and informative
<oats> I've just stumbled across some type thing that I don't understand, what's the difference between a *T pointer and this strange [*]T pointer?
<MajorLag> *T is a pointer to a single T, [*]T is a pointer to an unknown number of T
<MajorLag> For instnace, *u8 is a pointer to a single byte. [*]u8 is a pointer to an unknown number of bytes, most likely a null terminated C-string.
<oats> ah, gotcha
<oats> Thanks :)
<oats> Does that mean that stuff like pointer arithmetic isn't available for *T ?
<MajorLag> Right.
_whitelogger has joined #zig
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
raoof has joined #zig
<raoof> hi and thanks andrew and everybody else for making a cool language. I have a question, I have png file and I wanted to read the file and parse it at compile time, is it possible?
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
raoof has quit [Quit: Page closed]
davr0s has joined #zig
<hryx> raoof, take a look at @embedFile() - https://ziglang.org/documentation/master/#embedFile
<daurnimator> hryx: they left
<hryx> too true
<daurnimator> hryx: though I think their question is still useful to me
<daurnimator> ==> Can you e.g. call libpng at compile time?
<hryx> ooh, that's a good question, I don't know if you can call extern/C functions at compile time
raoof has joined #zig
raoof has left #zig [#zig]
m4r35n357 has joined #zig
SergeiMinaev has joined #zig
raoof has joined #zig
<raoof> hryx, thanks I'm using @embedFile I meant calling libpng to avoid decoding png at runtime
<m4r35n357> Can zig parse command line arguments? I couldn't find anything in the documentation section. (I am probably here prematurely, but I have a short c program that I would be interested in converting if that is feasible)
<m4r35n357> BTW I am motivated to try zig as a replacement for c, with native 128 bit floats. And yes, my problem domain does benefit from the extra precision!
wootehfoot has joined #zig
return0e_ has joined #zig
return0e has quit [Ping timeout: 252 seconds]
Zaab1t has joined #zig
affinespaces has joined #zig
aquiandres has joined #zig
return0e_ has quit [Read error: Connection reset by peer]
SergeiMinaev has quit [Quit: Page closed]
return0e has joined #zig
<MajorLag> You cannot call library functions at compile time. I did write a pure zig png library, but a) it's really sloppy and needs a lot of rework I haven't done yet, and b) it requires an allocator, which currently doesn't work at comptime either. What I've done in one of my demos is have an extra build step to pre-process assets into the memory layout I want, then dump that to a file that is @embedFile'd into the main pr
jmiven has quit [Quit: co'o]
<raoof> MajorLag, thanks good to know
jmiven has joined #zig
m4ge123 has quit [Read error: Connection reset by peer]
jmiven_ has joined #zig
jmiven has quit [Quit: co'o]
jmiven_ has quit [Quit: co'o]
jmiven has joined #zig
_whitelogger has joined #zig
m4ge123 has joined #zig
<oats> what's the reason for the change in struct syntax?
<oats> struct.{ ... }
<hryx> oats: That was done to resolve a syntactic ambiguity having to do with function return types. There's an issue for it somewhere. But it's probably going to be reverted soon after the problem is solved a different way
<oats> hryx: does this mean that single-expression functions don't need braces?
<oats> oh wait, never mind
<oats> I misread the issue
<oats> I see why this is a problem
<oats> fwiw, I like Hejsil's solution the best so far
<hryx> totally, I think that's the one that's gonna happen
<hryx> here's the work on it https://github.com/ziglang/zig/pull/1685
<oats> awesome
<oats> another question, how does one separate code into multiple files?
<oats> I can't find any documentation on how that works
benjikun has joined #zig
raoof has quit [Ping timeout: 256 seconds]
<hryx> oats: You always need one root file (e.g. "main.zig") which is the target of `zig build-exe`. That file can include other files with @import("other/file.zig"). Any files in your source tree which don't end up getting imported like this aren't compiled -- this means tests in those files won't get run either
wink_ has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
<oats> hryx: makes sense, thanks :)
<hryx> I was originally confused by the fact that you have to have exactly one root file (instead of `build [file1] [file2] ...`), but I like it now :>
<oats> I love compilers that are build systems
<oats> I've about made enough makefiles
aquiandres has quit [Read error: Connection reset by peer]
<oats> what's the difference between a struct field and a plain variable declared in a struct?
<oats> also, what's zig's polymorphism story? is there one yet?
<benjikun> does the `@import("std").build.Builder;` stuff work at compile-time
<MajorLag> oats, a struct field is an instance variable, a variable declared in a struct is just namespaced to that struct type. Zig has polymorphic functions using comptime parameters or the 'var' keyword. For the latter, see "printValue" under Case Study: printf in Zig (https://ziglang.org/documentation/master/#Case-Study-printf-in-Zig).
Zaab1t has quit [Quit: bye bye friends]
steveno has joined #zig
return0e has quit []
return0e has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
_whitelogger has joined #zig
<shachaf> hryx: I get a syntax error building build.zig for that tetris repository -- has the syntax changed or something?
<shachaf> Oh, it works with 0.3.0 but not 0.3.0+ef5d7ce4
DJoubert has joined #zig