<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)
<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
<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
<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
<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>
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
<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]
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]