ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<unique_id> i should probably just dereference when calling the function or possibly make the function take ptr to const if its a local one. These kinds of corner cases are unavoidable.
<wilsonk> does zig have a builtin isalpha function?
kristate has joined #zig
<kristate> woke up 10am JST
MajorLag has joined #zig
zolk3ri has quit [Quit: leaving]
scientes has joined #zig
<scientes> does zig have attribute(cleanup)?
<kristate> scientes: hello, can you rephrase your question?
<scientes> he cleanup attribute runs a function when the variable goes out of scope.
<kristate> scientes: please checkout the defer keyword: https://ziglang.org/documentation/master/#defer
<kristate> scientes: also look into the errdefer keyword: https://ziglang.org/documentation/master/#errdefer
<kristate> scientes: does that help you?
qazo has joined #zig
<scientes> yes
<scientes> also @firldParentPtr is awesome
<scientes> you don't see the magic of linux's container_of() get used much outside the kernel
qazo has quit [Ping timeout: 268 seconds]
<scientes> and is impossible in go and IIRC rust
<kristate> scientes: exactly.
<kristate> scientes: welcome to the community :-)
qazo has joined #zig
qazo has quit [Ping timeout: 244 seconds]
qazo has joined #zig
cryptonix2 has joined #zig
cryptonix2 has left #zig ["WeeChat 2.0.1"]
qazo has quit [Ping timeout: 244 seconds]
<scientes> the translate-c is out of date and produces struct.?.member code
<scientes> instead of orelse
<scientes> wait that seems wrong, is ? a safe dereference operator?
<scientes> so nvm
<MajorLag> unique_id: `const nothing = ([]void{})[0..];` `void` can be replaced by any type you might need.
<MajorLag> wait... nevermind that, I was reading a really old chat log somehow
<MajorLag> ...or not...
<MajorLag> whatever, I'm too tired to make sense I guess.
<scientes> is there a special case for "self" in struct methods?
<scientes> cause dot has two arguments, and then is used with one argument (and two).....???
<andrewrk> scientes, `a.b(arg1, arg2)` is syntax sugar for `@typeOf(a).b(a, arg1, arg2)`
kristate has quit [Ping timeout: 240 seconds]
kristate has joined #zig
return0e_ has joined #zig
return0e has quit [Ping timeout: 248 seconds]
davr0s has joined #zig
kristate has quit [Ping timeout: 260 seconds]
zolk3ri has joined #zig
kristate has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
<unique_id> MajorLag: thanks!
<unique_id> An inheritance feature could allow us to go from parent.base.field to parent.field. I have an additional use case for why this might be useful and that's to wrap types like ArrayList to handle OOM error in the wrapper and exit the program. This is wildly inappropriate for many applications, but for others not exiting just brings performance issues and noise from handling errors that you have no reason to handle. If the OS didn't
<unique_id> clean up for us things would be different of course, then propogating up would be needed.
qazo has joined #zig
qazo has quit [Read error: Connection reset by peer]
rom1504 has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
jjido has joined #zig
kristate has quit [Remote host closed the connection]
jjido has quit [Ping timeout: 240 seconds]
return0e has joined #zig
return0e_ has quit [Ping timeout: 256 seconds]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
zolk3ri has quit [Ping timeout: 250 seconds]
zolk3ri has joined #zig
<kristate> andrewrk: let me known when you're up, have some questions
return0e has quit [Ping timeout: 240 seconds]
return0e has joined #zig
SimonNa has joined #zig
l1x has joined #zig
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
darithorn has joined #zig
darithorn has quit [Client Quit]
<scientes> tree.insert(&(ns[0].node));
<scientes> tree.insert(ns[1].node);
<scientes> ^
<scientes> hello.zig:39:16: error: expression value is ignored
<scientes> tree.insert(&(ns[0].node));
<scientes> hello.zig:40:22: error: expected type '*Node', found 'Node'
<scientes> tree.insert(ns[1].node);
<scientes> pub fn insert(tree: *Tree, node: *Node) ?*Node {
<scientes> what does "expression value is ignored" mean?
<scientes> OH!
<unique_id> it means insert is returning something which you are ignoring. If you wish to ignore it explicitly, you can do "_ = tree.insert(...)"
<scientes> thats why i said "OH!
<scientes> how best to do this so zig accepts it?:
<scientes> if (parent != null) {
<scientes> parent.set_child(node, is_left);
<unique_id> if (maybe_parent) |parent| {parent.set_child(...); }
<unique_id> if (parent) |new_name|
<unique_id> or you can do:
<unique_id> if (parent != null) {
<unique_id> parent.?.set_child(node, is_left);
<unique_id> but that's strange and stupid I guess you could say, in debug mode that dereference would be checked
<unique_id> dereference/unwrap/whatever it's called
<scientes> can i do a compound if, like (maybe_parent && other > condition) |parent| { ?
<unique_id> I don't know, I guess not
<scientes> then i will if (maybe_parent != null) { var parent: ???
<scientes> how do i do that cast?
<unique_id> Maybe this works for you: if (maybe_parent != null and other > condition) { var parent = maybe_parent.?; }
<unique_id> I guess this would work too: if (maybe_parent and other > condition) { var parent = maybe_parent.?; }
<unique_id> btw there's unusually few people around here right now
<unique_id> please note how "and" is used instead of "&&"
<scientes> oh, i'm a C programmer :)
<scientes> maybe types do not cast to bool
<scientes> maybe they should
ofelas has joined #zig
<scientes> pub fn insert(tree: *Tree, node: *Node) ?*Node {
<scientes> node = grandpa;
<scientes> rror: cannot assign to constant
<scientes> how do i make these variables?
<scientes> it is because sometimes zig passes by value?
<unique_id> no, as far as I know you can not alter parameters. So you'd have to make a copy of the node pointer first
<unique_id> it makes a lot of sense to me to have that restriction by default, the question then is whether it's worth it to add a feature to mark the parameter as mutable
<andrewrk> unique_id, marking a parameter as mutable doesn't make sense because the way that would be implemented would be equivalent to `var mutable_param = param;` and then using mutable_param
<andrewrk> so you may as well just do that if you need a mutable parameter
<andrewrk> kristate, you still up?
very-mediocre has joined #zig
SergeiMinaev has joined #zig
<wink_> andrewrk: I like a thread to wait on a queue of messages until one arrives, but I don't see a mutex & condition variable or the like to sleep/wakeup a thread,did I miss it or do I need to make my own?
<andrewrk> wink_, mutexs and condition variables are not yet provided by the std lib
<wink_> k, I'll do my own for now and if you'd like create a PR.
<andrewrk> sure, just note that I'll leave it open until I can complete the macos and windows implementations too
<wink_> yep, np. I may make it universal, but for now just on linux.
<wink_> one step at a time :)
<scientes> while (node.get_parent()) |parentconst| {
<scientes> why does parentconst have to be immutable?
<scientes> i'm trying to loop over it
<unique_id> |*parent*
<unique_id> |*parent|
<unique_id> that's one solution
<unique_id> i'm sorry that's for for loops, no clue what that's doing in this case
<andrewrk> it also works for if and while
<scientes> can you give me an example
<andrewrk> var opt_x: ?i32 = 1234; if (opt_x) |*x| x.* += 1;
kristate has quit [Remote host closed the connection]
<wink_> I'm looking at std/atomic/queue.zig and there are private global functions, startPuts and startGets, can I assume when building an executable that these functions are optimized away?
<andrewrk> wink_, the optimizer doesn't even see them, because they're not even analyzed because they're only referenced in the test code
<andrewrk> zig has lazy top level declarations. if you don't reference something, it doesn't get compiled
<wink_> got it, so global variables to test shared state, will they be optimized away too?
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
davr0s has joined #zig
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
<scientes> why doesn't assignement return the variable?
<scientes> to prevent crazy c constructs??
<scientes> :)
very-mediocre has quit [Quit: Page closed]
wilsonk has quit [Read error: Connection reset by peer]
SergeiMinaev has quit [Ping timeout: 252 seconds]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
zolk3ri has quit [Ping timeout: 250 seconds]
zolk3ri has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<Dirkson> Weird question: Are coroutines concurrent yet? The description in the documentation only covers behavior that would be the same with concurrent and non-concurrent coroutines.
davr0s has joined #zig
wilsonk has joined #zig
<wilsonk> Test
<unique_id> andrewrk: My stack trace is telling me that the originator of a "index out of bounds" issue is "return self.items[0..self.len]" from a .toSlice() call. I know I've written buggy code and I can get around it / fix it, but I'm not sure how creating a slice could result in an index out of bounds crash? Reading from the slice sure, but creating it?
<unique_id> Ok the pointer which the slice is being created from is null, I can understand crashing on that. And indeed it is a bug, I don't know how that happened!
<unique_id> Though in other cases I've been creating slices that point to nothing.
<unique_id> or maybe the pointer isn't null. Time to debug properly.
MajorLag has quit [Ping timeout: 260 seconds]
MajorLag has joined #zig
<unique_id> ok my root issue was |child| should have been |*child|, I managed to return a pointer to something on the stack. My bad.
kristate has joined #zig
<kristate> woke up 8:30am JST
<kristate> scientes: cool -- do you have test cases?
<scientes> only smoke testing
<scientes> i'll make something up with rand()
<kristate> scientes: docs don't have much on testing I see
<kristate> search for `test "` on the docs page
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<scientes> can I use shared state between tests, or should i just make it one test?
<kristate> scientes: that is a good question -- state should be sharable between tests
<kristate> I think the rule of thumb is that if shared state could botch the test, don't use it
davr0s has joined #zig
<scientes> how do i do first class functions?
<kristate> scientes: for callbacks, etc?