ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
l1x has quit [Quit: Connection closed for inactivity]
ur5us has quit [Ping timeout: 264 seconds]
ky0ko has joined #zig
jacobsandlund has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
adsr has quit [Quit: WeeChat 3.1-dev]
ur5us has joined #zig
mokafolio has quit [Quit: Bye Bye!]
adsr has joined #zig
mokafolio has joined #zig
mokafolio has quit [Client Quit]
jacobsandlund has joined #zig
jacobsandlund has quit [Client Quit]
gazler has quit [Ping timeout: 258 seconds]
jacobsandlund has joined #zig
proteusguy has quit [Ping timeout: 264 seconds]
nycex has quit [Quit: Quit]
nycex has joined #zig
jacobsandlund has quit [Quit: Textual IRC Client: www.textualapp.com]
proteusguy has joined #zig
bitmapper has joined #zig
mokafolio has joined #zig
ur5us has quit [Ping timeout: 264 seconds]
xackus has quit [Read error: Connection reset by peer]
xackus has joined #zig
ur5us has joined #zig
rocket_man has joined #zig
* rocket_man waves
<rocket_man> how do I read from stdin in Zig? I found https://stackoverflow.com/questions/62018241/current-way-to-get-user-input-in-zig but it doesn't work in 0.8.0-dev
<rocket_man> ./src/main.zig:2:32: error: no member named 'inStream' in struct 'std.fs.file.File'
<daurnimator> rocket_man: was renamed to .reader()
<rocket_man> that worked, thanks :)
<rocket_man> yay and you fixed the bug that made me switch from 0.6 xD
<rocket_man> it would abort if stdin was closed (with 0<
<rocket_man> * 0<&-
<rocket_man> trying to do advent of code in zig (a little late)
<daurnimator> I only got up to day 10 or so :(
<rocket_man> haha, well I originally tried in haskell and I only got to like day 5 there
<rocket_man> couldn't figure out how to use hashmaps
<rocket_man> hmm, how do I use an iterator of unknown length? I tried a `for` loop and got './src/main.zig:14:3: error: no member named 'len' in struct 'std.mem.SplitIterator''
<rocket_man> (or if this is an X Y problem and there's an easier way to say "for line in stdin" do let me know)
<daurnimator> rocket_man: you have to use a while loop
<rocket_man> thanks
<rocket_man> seems weird the for loop doesn't do that by default but ¯\_(ツ)_/¯
<rocket_man> also it's slightly confusing that `const x = getStdOut().getOutStream()` will compile fine until you try to actually use it
<rocket_man> here's a feature I'd like - I got an error just now that 'expression value is ignored' for `try stdout.write(line);`. I was confused because I had `try`, but it turns out the issue is that I was ignoring the number of bytes written. In rust, there's `#[must_use = "write may not write all bytes"]`, it would be nice to have that in zig
<rocket_man> (the fix was to use writeAll instead)
xackus_ has joined #zig
<kameliya> rocket_man: the "will compile fine until you actually use it" turns out to be a big part of how zig can do magic comptime stuff. it still trips me up sometimes despite knowing.
xackus has quit [Ping timeout: 272 seconds]
<rocket_man> hmm, the compiler seems to have gotten stuck - it's been compiling for like a solid minute
<rocket_man> I just have a trivial 16 line program
<rocket_man> oh wait the program it compiled was reading stdin, I'm dumb lol
<kameliya> haha
<rocket_man> wait, I can't even use for loops for lists? `./src/main.zig:20:3: error: no member named 'len' in struct 'std.array_list.ArrayListAligned(i64,null)'`
<kameliya> you want to iter over the `.items` member of the array list
<rocket_man> ah ok, thanks
<kameliya> np. `for' only iterates over arrays/slices, it won't do any method calls or anything.
<rocket_man> ok I see, ArrayList is a wrapper around a slice of unknown length
<rocket_man> makes sense
<kameliya> yep. it manages the `items' member and its backing storage for you, it'll always be a slice of the right length. (there may be more storage allocated behind it which arraylist keeps track of for you.)
<rocket_man> right, length vs capacity and all that
<kameliya> ya
<rocket_man> yay I finally got parsing and printing integers working xD only took me an hour
<kameliya> sweet! next time it'll take 5 minutes.
<rocket_man> I have to say it's super cool that `ArrayList.init` is just a function that takes a type
<rocket_man> no need to have generics if types are values haha
<kameliya> yeah, it ends up working super neatly in lots of ways
<kameliya> ime, comptime takes some time to get comfy with but you can express things traditional type-systems struggle to
<rocket_man> how does comptime work? is there like a compile time interpreter or something?
<kameliya> i think so, yeah. i haven't gone into the backend of it at all!
<rocket_man> hehe, well compilers are my passion so I'm always trying to figure out how they work
<rocket_man> hacked on the rust compiler for a while but I started to get tired of the awful compile times
<kameliya> there's a big rewrite in the works porting a lot of the compiler over from c++ to zig, good time to get involved!
<rocket_man> zig does a lot better there, it's awesome that it's so fast it doesn't even pre-compile the standard library
<rocket_man> haha, well I should probably learn zig first at all lol
<kameliya> ya hehe :)
<rocket_man> I see documentation for arrays in https://ziglang.org/documentation/master/#Arrays - is there documentation for slices?
<rocket_man> I want to know if an i64 is in an ArrayList
<rocket_man> std.mem.containsAtLeast looks about right
<rocket_man> little verbose though
<mikdusan> indexOfScalar(i64, &array_list, 4242)
<kameliya> rocket_man: thoroughly recommend you keep a tab with https://github.com/ziglang/zig open and become very familiar with the T hotkey -- the stdlib source (i.e. the stuff written in Zig itself) is extremely readable and better than docs right now
<rocket_man> mikdusan: ./solution.zig:14:3: error: expected type '[]const i64', found '*std.array_list.ArrayListAligned(i64,null)'
<mikdusan> ah nuke the ampersand
<kameliya> you also want to use `.items' to get at the slice in the arraylist
<rocket_man> kameliya: well searching the stdlib requires me to know the name of what I'm searching for
* mikdusan is still groggy. sorry missed it was a higher type ArrayList
<rocket_man> I was hoping the reference would have type signatures and such so I could look at those
<kameliya> rocket_man: indeed, so reading files like std/mem.zig and such tends to be fruitful.
ur5us has quit [Ping timeout: 272 seconds]
<rocket_man> oh interesting primitive values can be null too
<rocket_man> what does this mean? './solution.zig:20:3: error: variable of type '(null)' must be const or comptime'
<kameliya> can you share the code that's causing it?
<rocket_man> `var found = null;`
<kameliya> ah. `null' itself has no type, so you need to declare what nullable type it might be
<rocket_man> I want to search an array for a number, assign it to `found` if so, and have `found` be null otherwise
<rocket_man> ok, thanks
<kameliya> e.g. `var found: ?usize = null;'
<rocket_man> I guess zig doesn't have type inferrence then?
<mikdusan> it does but there's nothing to infer in your statement
<rocket_man> since I did assign to it in the loop
<kameliya> it does, but it doesn't go backwards.
<rocket_man> ah ok, it's one-way
<rocket_man> rust has spoiled me for type inference lol
<kameliya> yep. if you have a `fn blah() ?usize { ... }' somewhere and then `var x = blah();', `x' will now be a `?usize'.
<rocket_man> is there a 'list.find()' function that does this? seems like a really common pattern
<kameliya> are you wanting the index of a matching member?
<rocket_man> I want the member if it matches and `null` otherwise
<daurnimator> mem.indexOf ?
bitmapper has quit [Quit: Connection closed for inactivity]
<rocket_man> in rust this is `list.find(predicate)`
<rocket_man> no, indexOf doesn't allow a custom predicate
<daurnimator> zig discourages that functional type of approach
<daurnimator> use a loop
<kameliya> no predicates or lambdas, you will need to diy.
<rocket_man> hmm, ok
<kameliya> `var found: ?u32 = null; for (list) |e| { if (predicate) { found = e; break; } }'
<kameliya> something like that
<rocket_man> no lambdas? what's the `|x|` syntax for for loops then?
<daurnimator> rocket_man: that's a capture
<kameliya> you see them in switch, catch, if, while, etc. too
* rocket_man is confused
<daurnimator> yeah captures are essentially unexplained in the manual
<kameliya> yeah, they just come "for free" wherever they're used, lol
<daurnimator> `for (list) |x|` -> `x` is the value you're iterating over. you can also do `for (list) |x,i|` -> and you get the value and the index. you can also write `for (list) |*x|` to get a pointer to the item instead of a copy
<rocket_man> oh ok, compiler magic
<rocket_man> :P
<kameliya> rocket_man: wherever a block-ish expression introduces a new binding, captures |blah| tend to introduce the names for those bindings
<kameliya> more like syntax
<kameliya> i find this is a nice example
<kameliya> also because it shows how diy ergonomic iterators can work
<rocket_man> wait, so is the `break` there acting like `yield` in python?
<kameliya> no, that's .. a bit more magic too
<kameliya> you could write eventuallyNullSequence() like this:
<kameliya> if (numbers_left == 0) { return null; } else { numbers_left -= 1; return numbers_left; }
<rocket_man> ah ok, like labeled breaks in rust
<rocket_man> oh oh I'm being silly - eventuallyNull is called on every iteration of the loop
<rocket_man> there's nothing special about it, it's just a function
<kameliya> yep!
<kameliya> right, one that returns a nullable u32
<kameliya> when it returns null, the while loop breaks
<kameliya> when it isn't returning null, the non-null value is bound to the capture in the loop body
<rocket_man> nice, thanks :)
<kameliya> np
<rocket_man> hmm, zig seems to have forgotten that I just checked for null: `./solution.zig:29:43: error: invalid operands to binary expression: 'comptime_int' and '?i64'`
<rocket_man> for `std.debug.print("{} {}", .{found, 2020-found});`
<rocket_man> if I just print `found` it works fine
<daurnimator> you need to unwrap it
<daurnimator> you can use `.?` to assert its not-null. but that's rarely the best solution
<rocket_man> what's a better solution?
<rocket_man> I'm already checking for null, I just don't know the syntax
<daurnimator> `if (found) |value| { std.debug.print("{} {}", .{value, 2020-value}); }`
<rocket_man> ah interesting, `if` works with optionals too
<daurnimator> as does `while`
<rocket_man> booo the compiler doesn't like shadowing
<daurnimator> and btw, captures are for both optionals and errors
<rocket_man> yay I finished the first part of advent of code day one :)
<rocket_man> thanks for all the help!
<kameliya> yw! nicely done!
<rocket_man> why does zig use semicolons btw? it's not expression-oriented, if you leave it out it's just a syntax error
<daurnimator> rocket_man: redundancy
<rocket_man> it helps with error recovery in the parser or something?
<daurnimator> as in: you want some syntaxes to be invalid, so that 2 mistakes are required to write the wrong thing
<daurnimator> `foo() (someexpression)()` -> is this two expression or one?
<daurnimator> the answer *shouldn't* be: "it depends on the return type of foo()"
<daurnimator> for some languages the answer is "be greedy: it's one expression"
<rocket_man> well in rust it would be two :P and you have to disambiguate `(foo()(expression))()` if you want to call it twice
<daurnimator> rocket_man: no I was potentially calling the result of foo()
<rocket_man> you can solve the ambiguity without always needing semicolons
<rocket_man> hmm I was wrong before though, it treats it as 3 function calls in row
<daurnimator> rocket_man: and now put it on two line: `foo()\n(someexpression)()`
<rocket_man> oh you meant it the other way - it will be the same still though
<pjz> I wish zig would ignore extra semicolons, though; I tend to sprinkle them around a little if I'm uncertain of the exact grammar. Sprinkling around {}; isn't quite as nice :)
<daurnimator> rocket_man: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ff9c2abcc8f512ceabd135d39225dc61 now add a semicolon on line 6 to see why you need it
<rocket_man> ok I take the point
<rocket_man> how do I say 'a slice of i64'?
<daurnimator> []i64
<rocket_man> thanks
<daurnimator> btw, i64 is a pretty rare type to need
<rocket_man> as opposed to i32 you mean? probably yeah, but I figured better too big than too small
<daurnimator> rocket_man: I actually meant in terms of having it signed
<rocket_man> now that I'm surprised to hear xD
<daurnimator> use unsigned if negative numbers don't make sense (which is the majority of the time)
<rocket_man> although you're right, I could have made it unsigned in this case
<pjz> another popular choice is usize since you can index into slices with it
<daurnimator> you can index into slices with anything usize or smaller
<daurnimator> in general: pick the smallest integer type you can
<pjz> doing so lets zig optimize better, I think
<daurnimator> indeed. but it also helps you the developer by giving you errors if something is outside of the range you designed for
<rocket_man> well, I'm not worrying a ton about performance right now
<daurnimator> not to mention less memory usage
<pjz> true
<pjz> well, maybe less memory usage
<rocket_man> I don't know what you mean by 'designed for' in this context
<daurnimator> rocket_man: i.e. what's the biggest value you'll see? 5000? okay use a u13 then.
<rocket_man> well I don't know the largest value
<daurnimator> why not?
<rocket_man> it's just not part of the problem statement
<daurnimator> and if you truely don't know, then you better reach for the arbitrary precision bignum library
<rocket_man> heh
<pjz> rocket_man: you're doing aoc2020 ?
<rocket_man> pjz: yes
<pjz> rocket_man: download your input and you'll know :)
<rocket_man> daurnimator: I trust the authors not to give me *awful* numbers xD
<rocket_man> pjz: well right, but it's not worth bothering with if i64 will be big enough
<daurnimator> IIRC AOC was fine with a u1
<daurnimator> u16
<pjz> I used usize mostly for all the AOC I did
<pjz> (which was... *checks* ... 11)
<rocket_man> lol somehow I ended up with `-1318485525`
<rocket_man> I did *something* wrong
<rocket_man> oh I know what I did - how do I remove one element from a list at a time?
<rocket_man> I guess I could do `items[i..]` or something
<kameliya> is it an arraylist? do you want to actually mutate it or do you just want a new slice?
<kameliya> ArrayList has "orderedRemove(ix)"
<rocket_man> nah, [i..] was what I wanted
<kameliya> cool
<rocket_man> I just wanted to look at less of it
<rocket_man> still debugging why this behaves differently from my haskell solution though
<rocket_man> oh I forgot to multiply again lol
<rocket_man> doh
<rocket_man> and that's advent of code day 1 :)
<rocket_man> is there a way to tell `zig init-exe` to put the source file somewhere other than `src/main.zig`?
<rocket_man> bugs me when cargo does that too
<daurnimator> no
<daurnimator> and where do you want it instead?
<rocket_man> `solution.zig`
<rocket_man> in the rust world people have been tossing around the idea of 'templates' other than the default one
<rocket_man> anyway, just a paper cut, easy enough to edit build.zig
<rocket_man> is there something like `scanf` in zig? that takes a custom format string?
<andrewrk> not yet
<andrewrk> would be a nice addition
<andrewrk> so far our biggest use case for that is advent of code :)
<rocket_man> haha
<rocket_man> well, in fairness I expect a lot of uses in general come from advent of code xD
waleee-cl has quit [Quit: Connection closed for inactivity]
<rocket_man> andrewrk: if I wanted to add scanf how would I get started?
<rocket_man> (assuming I've read through https://github.com/ziglang/zig/blob/master/CONTRIBUTING.md and have the compiler working)
<rocket_man> kameliya: see, it only took me 3 hours to start working on the compiler xD
<daurnimator> rocket_man: recognise that `scanf` requires a peekable stream
<daurnimator> and therefore isn't suitable as a general stream method
<daurnimator> but instead should perhaps be on PeekableStream
factormystic has quit [Read error: Connection reset by peer]
<rocket_man> why does it need a peekable stream?
<rocket_man> I do see ungetc in https://github.com/esmil/musl/blob/194f9cf93da8ae62491b7386edf481ea8565ae4e/src/stdio/vfscanf.c#L79 but I don't know if that's a hard requirement or just easier to code
<daurnimator> because say you're reading a number: you read a byte: '1', you read a byte: '2', you read a byte: '@'... oops put that back; the number was 12
<rocket_man> ahh, makes
<rocket_man> *makes sense
<daurnimator> rocket_man: might be able to work from https://github.com/ziglang/zig/pull/7158
<daurnimator> its not the best starting point; but it might give you ideas for the parser state machinery
<rocket_man> wow 700 lines seems like a lot of code right now haha
<daurnimator> though really... you might want to start again from the code in fmt.zig
<daurnimator> rocket_man: scanf isn't simple :P
<rocket_man> maybe I should come back to this in a few weeks lol
<daurnimator> probably a good idea
<rocket_man> good night everyone, thanks again for all the help :)
rocket_man has quit [Quit: WeeChat 2.8]
<kameliya> night!
rocket_man has joined #zig
<rocket_man> ok I'm back - I forgot to give a giant thank you to andrewrk for inspiring me to download LLVM for rust contributors the way zig does it :) https://github.com/rust-lang/rust/pull/80932/
<rocket_man> @lokathor talked me into it
rocket_man has quit [Client Quit]
kbd has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
<andrewrk> nice :)
sord937 has joined #zig
gazler has joined #zig
cole-h_ has joined #zig
cole-h has quit [Ping timeout: 246 seconds]
decentpenguin has quit [Read error: Connection reset by peer]
decentpenguin has joined #zig
<kameliya> i’m 95% of the way from transferring control from my uefi bootloader (in zig) to a dummy os kernel (also zig), all on aarch64! much excite
<kameliya> just need to appease the mmu
cole-h_ is now known as cole-h
ur5us has joined #zig
cole-h has quit [Ping timeout: 264 seconds]
frarees has joined #zig
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
frarees has quit [Quit: Textual IRC Client: www.textualapp.com]
ur5us has quit [Ping timeout: 264 seconds]
<kameliya> hm.. i'm sure i know somewhere how @bitSizeOf(x) could equal 64 but @sizeOf(x) is 9
<kameliya> ah
<kameliya> packed structs
<kameliya> i see
<ifreund> kameliya: yeah, I recommend comptime asserts on the size/alignment of all of your packed structs with stage1
cCCCCcccccCCc has quit [Ping timeout: 256 seconds]
tnorth has joined #zig
bitmapper has joined #zig
ltr has joined #zig
waffle_ethics has joined #zig
xackus_ has quit [Ping timeout: 272 seconds]
<marler8997> someone one reddit is trying to compile a Zig library and call it from C, the docs say Zig will generate a C header file? Is that true?
<marler8997> I tried the example in the docs that says a ".h" file will be generated, but it doesn't appear to work, no header file to be found? Is it missing some command-line option/build config?
<ifreund> marler8997: this functionality was temorarily removed shortly before 0.7.0 in #6250. It's recently been reimplemented though in this PR: https://github.com/ziglang/zig/pull/7111
<ifreund> I haven't tested it though so I can't say how well it works in master but it should theoretically do something
<marler8997> thanks for the info
<mikdusan> I tried this: `zig build-lib z0.zig -femit-h` and:
<mikdusan> warning(compilation): -femit-h is not available in the stage1 backend; no .h file will be produced
<marler8997> yeah I got the same error, I'll let the reddit user know
<marler8997> would be nice to update the docs to indicate it's not supported
<ifreund> marler8997, mikdusan: you need to pass -fno-LLVM to use the self-hosted backend
notzmv has quit [Ping timeout: 260 seconds]
haliucinas has quit [Ping timeout: 256 seconds]
haliucinas has joined #zig
Xatenev has joined #zig
Akuli has joined #zig
ltr has quit [Ping timeout: 264 seconds]
ltr has joined #zig
LanceThePants has quit [Read error: Connection reset by peer]
sawzall has joined #zig
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
donniewest has joined #zig
mokafolio has quit [Client Quit]
ltr has quit [Quit: leaving]
mokafolio has joined #zig
mokafolio has quit [Client Quit]
waleee-cl has joined #zig
factormystic has joined #zig
nvmd has quit [Ping timeout: 240 seconds]
nvmd has joined #zig
mokafolio has joined #zig
mokafolio has quit [Client Quit]
mokafolio has joined #zig
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
mokafolio has quit [Client Quit]
mokafolio has joined #zig
mokafolio has quit [Client Quit]
tnorth has quit [Ping timeout: 258 seconds]
mokafolio has joined #zig
mokafolio has quit [Client Quit]
mattmurr___[m] has quit [Quit: Idle for 30+ days]
mokafolio has joined #zig
hnOsmium0001 has joined #zig
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
mokafolio has quit [Client Quit]
mokafolio has joined #zig
mokafolio has quit [Client Quit]
kbd has joined #zig
techtirade has quit [Read error: Connection reset by peer]
mokafolio has joined #zig
techtirade has joined #zig
di-wu is now known as quint
quint is now known as di-wu
<paulsmith> is it intended that std.io.Writer be an interface like std.mem.Allocator? i was surprised that this didn't work the way i expected: https://gist.github.com/paulsmith/12b87b22fe7d43d6997243a02e89afaf
<ifreund> paulsmith: no, std.io.Writer() is a function not a type. You probably just want to use anytype there
<paulsmith> ifreund: ok, that worked, thanks
nvmd has quit [Ping timeout: 240 seconds]
nvmd has joined #zig
<ifreund> no problem!
nvmd has quit [Ping timeout: 264 seconds]
nvmd has joined #zig
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
ltr has joined #zig
kbd_ has joined #zig
kbd has quit [Ping timeout: 272 seconds]
ky0ko has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
ky0ko has joined #zig
<ikskuh> andrewrk: do you happen to know where std.c.getpeername went? :D
<andrewrk> ikskuh, it didn't go anywhere; it never existed
<ikskuh> huh
* ikskuh is now confused
<ikskuh> why the heck did that project *ever* compile then?!
<ikskuh> i am confused :D
<ifreund> maybe you added the extern def for it and forgot to send a PR :P
<ikskuh> haha
<ikskuh> that's a possiblity
ur5us has joined #zig
cole-h has joined #zig
sord937 has quit [Ping timeout: 240 seconds]
nycex has quit [Quit: Quit]
nycex has joined #zig
sord937 has joined #zig
nycex has quit [Remote host closed the connection]
nycex has joined #zig
cCCCCcccccCCc has joined #zig
bitmapper has quit [Quit: Connection closed for inactivity]
cole-h has quit [Quit: Goodbye]
cole-h has joined #zig
ur5us has quit [Ping timeout: 264 seconds]
ur5us has joined #zig
Akuli has quit [Quit: Leaving]
alvv___ has joined #zig
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
raggi has quit [Ping timeout: 260 seconds]
sord937 has quit [Quit: sord937]
raggi has joined #zig
wootehfoot has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
donniewest has quit [Quit: WeeChat 3.0]
osa1 has quit [Remote host closed the connection]
osa1 has joined #zig
Xatenev has quit [Remote host closed the connection]