ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
schme245 has joined #zig
kristate has joined #zig
kristate has quit [Ping timeout: 240 seconds]
schme245 has quit [Remote host closed the connection]
peekazig has joined #zig
peekazig has quit [Client Quit]
wootehfoot has quit [Quit: Leaving]
kristate has joined #zig
wilsonk has quit [Ping timeout: 246 seconds]
wilsonk has joined #zig
wilsonk has quit [Ping timeout: 246 seconds]
return0e_ has joined #zig
return0e has quit [Ping timeout: 268 seconds]
darithorn has quit [Quit: Leaving]
noonien has quit [Quit: Connection closed for inactivity]
_whitelogger has joined #zig
schme245 has joined #zig
marmotini_ has joined #zig
schme245 has quit [Read error: Connection reset by peer]
schme245 has joined #zig
marmotini_ has quit [Ping timeout: 245 seconds]
marmotini_ has joined #zig
marmotini_ has quit [Ping timeout: 268 seconds]
_whitelogger has joined #zig
wilsonk has joined #zig
marmotini_ has joined #zig
marmotini has joined #zig
marmotini_ has quit [Ping timeout: 250 seconds]
Ichorio has joined #zig
Zaab1t has joined #zig
wootehfoot has joined #zig
Ichorio has quit [Read error: Connection reset by peer]
Ichorio has joined #zig
marmotini has quit [Remote host closed the connection]
marmotini has joined #zig
marmotini has quit [Remote host closed the connection]
marmotini has joined #zig
marmotini has quit [Remote host closed the connection]
marmotini_ has joined #zig
marmotini_ has quit [Remote host closed the connection]
noonien has joined #zig
darithorn has joined #zig
kristate has quit [Remote host closed the connection]
forgot-password has joined #zig
<forgot-password> Is it possible to have a switch on a union modify the contained data?
<forgot-password> The compiler says that it expects a `*A`, but found a `*const A` and I don't know how to get a non-constant pointer out of my active union.
<andrewrk> forgot-password, yes - assuming you mean a tagged union
<andrewrk> https://ziglang.org/documentation/master/#union - search for the comment "Capture by reference"
<forgot-password> Yes, I have a tagged union
<andrewrk> this should be more clear in the docs. I'll make a note of it
<forgot-password> Huh, I tried that, but I still get the same message
<andrewrk> you may have a const reference to your union
<andrewrk> can I see the code?
<forgot-password> I should probably also mention that I iterate through an ArrayList of which I obtain a slice via `.toSlice`
<forgot-password> And on every union in that slice I call a function, which has this signature: `pub fn update(self: MyUnion) void`
<forgot-password> Does that function have to take a pointer to `MyUnion` for mutation to work?
andrewrk has left #zig ["Leaving"]
andrewrk has joined #zig
<andrewrk> forgot-password, parameters cannot be modified
<andrewrk> so that's the problem here - that's why the reference is const
<forgot-password> So what I'm trying to do is not possible at all? Afaik I cannot turn a `const A` into a `*A`, only in a `*const A`, right?
<andrewrk> correct
<andrewrk> think about it this way - when you see: `fn update(self: MyUnion) void` you, the person reading the code, may assume that `self` is never mutated in this function
<andrewrk> zig is designed to give the person reading code as many assumptions as possible
<daurnimator> andrewrk: I do think that's sort of weird
<daurnimator> andrewrk: e.g. fn dothething(x: u32) { while(x>0) : (x -= 1) { doit(); } } // this seems like a natural way to write a 'do X times' loop
<andrewrk> I think you'll be fighting a pretty uphill battle to get mutable parameters
<daurnimator> andrewrk: it's weird to me that `const` is then required on parameters
<daurnimator> *isn't
<daurnimator> why aren't you forced to write: fn dothething(x: const u32) { ..... }
<andrewrk> just as part of the syntax for function prototypes? what would be the point of that?
<daurnimator> or if that's too verbose... why isn't `const` compulsory all the time? (and require `mut`)
<andrewrk> that syntax is not valid in a variable declaration: var x: const u32 = 124; // syntax error
<daurnimator> it is just one of those weird inconsistencies
<daurnimator> andrewrk: right... it's `const x:u32 = fromsomewhere`
<daurnimator> Maybe I'm just getting confused by `const` being overloaded as a keyword
<andrewrk> it's not out of the question that `const` as a variable declaration gets replaced by `let`
<companion_cube> \o/
<forgot-password> I'm such a moron, I just noticed that I can capture the items in the slice by reference as well... Thank you :)
<andrewrk> forgot-password, no need to beat yourself up. glad you got it working
<andrewrk> daurnimator, I don't think "inconsistent" is a fair characterization. where else in the language can you pass a parameter and have it be mutable?
<andrewrk> or, better phrased, what is it inconsistent with?
<daurnimator> andrewrk: sorry, I got confused about `const`
<daurnimator> andrewrk: forgot that `const` was part of a variable declaration; not part of the type..... unless it is part of the type; but that's at a level of indirection
<andrewrk> const is a part of pointer types
<daurnimator> andrewrk: and arrays?
<andrewrk> no
<andrewrk> only pointer types
<daurnimator> oh right
<daurnimator> okay so yes. the confusion is that `const` is a property/keyword of a pointer type, as *well* as a way to declare variables
<daurnimator> clearly one of them needs to change :)
<andrewrk> got it. that's a good argument for `let`
<andrewrk> the other good argument for `let` is that it's the same number of keystrokes as `var`, encouraging its use
<companion_cube> another step towards rust? :)
<companion_cube> (rust's syntax, that is)
<andrewrk> yes, but I don't think we would do the `mut` keyword
<daurnimator> btw, my "and arrays" comment was because I thought of `[]const u8`, and the `[]` made me think "that's an array". but really it's a pointer type
<companion_cube> I guess `let` and `var` are fine indeed
<andrewrk> right. it's a bit confusing. the issue that makes array literals with inferred size [_] instead of [] should help
<companion_cube> `mut` allows to write `fn foo(mut x: T)` but you don't seem to like it :)
<andrewrk> I will note that if you look at `zig builtin`, the @typeInfo for a slice puts it in the Pointer category
<andrewrk> companion_cube, zig also does not have "byval" parameters
<daurnimator> andrewrk: so (sort of as companion_cube said): what about `fn foo(var x: u32)` for a mutable arg
<andrewrk> well, I suppose it does for integers. but when you pass a struct as a parameter, zig is allowed to secretly pass a reference, or a copy
<andrewrk> daurnimator, that would require "byval" parameters
<daurnimator> andrewrk: howso?
<companion_cube> so arguments are passed by reference, at least semantically?
<daurnimator> andrewrk: it would still always be a copy (or secret reference). but you could mutate your copy
<andrewrk> mutable parameters, if they were structs or arrays, would require a hidden memcpy at the callsite.
<andrewrk> right now, when you pass parameters to functions, there is no hidden memcpy. if you want a copy, you have to do it yourself
<daurnimator> andrewrk: semantically yes.
porky11 has joined #zig
<porky11> is it possible to define a generic function without having to specify the type explicitly?
<daurnimator> porky11: use `var` as the type?
<daurnimator> porky11: https://ziglang.org/documentation/master/#Case-Study-printf-in-Zig see the `printValue` example function?
wilsonk has quit [Ping timeout: 250 seconds]
<porky11> daurnimator, but that's not available in 0.3.0 yet, right?
<porky11> I got TODO implement inferred return types https://github.com/ziglang/zig/issues/447
<daurnimator> porky11: ah you're asking about the return type in particular?
<porky11> It's not important, if there is another way to define such a function.
<porky11> I just want to write `max(1, 2)` instead of `max(u32, 1, 2)`
<porky11> I probably could get it to work with @typeOf
<porky11> So I want to define some kind of vector math, where different vector types can be multiplied and the result type depends on the argument types, and I don't want to rewrite all types
marmotini_ has joined #zig
porky11 has quit [Ping timeout: 240 seconds]
marmotini has joined #zig
marmotini_ has quit [Ping timeout: 240 seconds]
marmotini_ has joined #zig
marmotini has quit [Ping timeout: 244 seconds]
Akuli has joined #zig
forgot-password has quit [Ping timeout: 250 seconds]
<emekankurumeh[m]> you could try making the return type `@typeOf` one of the var parameters.
<emekankurumeh[m]> like `fn max(a: var, b:@typeOf(a)) @typeOf(a)`
<emekankurumeh[m]> i haven't tested if that's valid syntax though
<schme245> it does
<schme245> or it is, rather
wilsonk has joined #zig
wilsonk has quit [Ping timeout: 250 seconds]
wootehfoot has quit [Ping timeout: 240 seconds]
schme245 has quit [Remote host closed the connection]
schme245 has joined #zig
kristate has joined #zig
Akuli has quit [Quit: Leaving]
wilsonk has joined #zig
schme245 has quit [Remote host closed the connection]
schme245 has joined #zig
schme245 has quit [Remote host closed the connection]
wilsonk has quit [Ping timeout: 246 seconds]
Ichorio has quit [Ping timeout: 250 seconds]
marmotini_ has quit [Ping timeout: 250 seconds]
kristate has quit [Remote host closed the connection]
forgot-password has joined #zig
forgot-password has quit [Quit: leaving]
wilsonk has joined #zig