ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
hoppetosse has joined #zig
wilsonk_ has joined #zig
wilsonk_ has quit [Client Quit]
<dbandstra> how do i use zig fmt...? i finalyl decided to check it out but i realized i have no idea where it is
wilsonk has quit [Ping timeout: 252 seconds]
<GitHub10> [zig] andrewrk pushed 1 new commit to master: https://git.io/fNvKp
<GitHub10> zig/master ced3aae Andrew Kelley: cleaner output from zig build when there are compile errors
wilsonk has joined #zig
hoppetosse has quit [Ping timeout: 264 seconds]
tiehuis has joined #zig
<tiehuis> dbandstra: for now `zig fmt` is only present in the stage2 compiler so you need to build that
<tiehuis> there are instructions at the bottom of the README
hooo has quit [Quit: Connection closed for inactivity]
meena has quit [Ping timeout: 255 seconds]
<dbandstra> tiehuis, thanks
<dbandstra> has anyone managed to get it integrated with vs code?
<tiehuis> i don't think so, i did it with vim but don't use vscode personally so it isn't on my list
<tiehuis> i'll have a look sometime today though and if it isn't too much work i can add an autofmt option
<tiehuis> made an issue for it https://github.com/ziglang/vscode-zig/issues/6
<tiehuis> thanks, that will be helpful
davr0s has joined #zig
meena has joined #zig
v1zix has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
v1zix has quit [Ping timeout: 252 seconds]
<dbandstra> is it possible to create a zero-length slice in the middle of an expression, without having to refer to any memory?
<dbandstra> this almost works `const y: []u32 = ([0]u32{})[0..];` but doesn't compile becaues the expression has type `[]const u32`
<dbandstra> (i want it to be `[]u32`)
<tiehuis> separating those statements seems to work: e.g. `var y = [0]u32{}; var z: []u32 = y[0..];`
<tiehuis> may be a better way to do that but not sure
<GitHub33> [zig] thejoshwolfe pushed 1 new commit to master: https://git.io/fNvXB
<GitHub33> zig/master 410b4d9 Josh Wolfe: builder.addBuildOption
<dbandstra> i want to return this from a function and it feels wrong to return a slice of a local even if it's 0 length
fjvallarino has quit [Remote host closed the connection]
<dbandstra> oh well
fjvallarino has joined #zig
fjvallarino has quit [Ping timeout: 264 seconds]
davr0s has joined #zig
donlzx has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
_whitelogger has joined #zig
dbandstra has quit [Quit: Leaving]
andi3 has joined #zig
<andi3> @Hejsil the main pro point Blow mentioned as well is that for loops are such a common building block und using coroutines makes it much easier to reason about them (replace the `visit` function with `yield`), of course you can not delete or insert this way but many times you just want to find/ modify/ filter a range and in those cases you have to do less work/ less errors as can be seen at about min 6 left vs right side
<andi3> and I'd like to point out the headline of this irc being `be excellent to each other`, saying "watching someone talking In his underwear" is not exactly excellent
andi3 has quit [Client Quit]
davr0s has joined #zig
_whitelogger has joined #zig
alexnask_ has joined #zig
Bas_ has joined #zig
fjvallarino has joined #zig
fjvallarino has quit [Ping timeout: 248 seconds]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
zolk3ri has joined #zig
donlzx has quit [Quit: Leaving]
enoent has joined #zig
_whitelogger has joined #zig
qazo has joined #zig
hoppetosse has joined #zig
qazo has quit [Ping timeout: 244 seconds]
qazo has joined #zig
Bas_ has quit [Ping timeout: 252 seconds]
qazo has quit [Ping timeout: 245 seconds]
Bas_ has joined #zig
<Bas_> If you have a single struct. How do you copy it byte-wise to a byte arrray/slice?
<Bas_> I'm trying to use std.mem.copy, but it wants a slice and ... well I don't have a slice, I only have one thing.
<Bas_> Taking the address doesn't work, because a pointer is not a slice, and I can't make the pointer into a slice because it says it's a single-item pointer.
davr0s has joined #zig
enoent has quit [Ping timeout: 252 seconds]
<tiehuis> Bas_: you can do this: `const ptr = @sliceToBytes(([]const Foo{a})[0..1]);`, where Foo is your struct type and a is a value of type Foo
<tiehuis> that is a bit awkward, i think there should be a more straight-forward way using @ptrCast or something but it is eluding me; don't usually do slice casting and the like
<tiehuis> also, remember to make sure you use a `packed struct` since the ordering of fields isn't guaranteed otherwise
<Bas_> Hmm... yes that's a bit awkward.
<tiehuis> if you make that an inline fn it can at least hide away some of the messiness for the moment
<Bas_> I tried bitcast, but that crashed
<tiehuis> yeah, bitCast won't work since you just want a re-intepretation of the memory and not a new copy, right?
<tiehuis> also, it doesn't work for arrays just yet
<Bas_> yes
<Bas_> I just want to copy the struct to a byte buffer.
<tiehuis> copied to a new array?
<Bas_> a slice of an existing one.
Tobba has quit [Remote host closed the connection]
Tobba has joined #zig
<tiehuis> here are two variants for any type, one returning a slice/view and another a new array copy: https://clbin.com/Xa6nB
<Bas_> Ah cool. Thanks.
<tiehuis> the second one should eventually work as you expect via @bitCast
tiehuis has quit [Quit: WeeChat 2.1]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
very-mediocre has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
<very-mediocre> any way to use `@setEvalBranchQuota` for an implicitly comptime const (declared outside of functions/structs)
<very-mediocre> say for instance you want to generate a lookup table of prime numbers at comptime, for use at runtime
<very-mediocre> doing it like `comptime { const primes = genPrimes(100); }` means `primes` becomes unusable at runtime
<MajorLag2> `const primes = comptime val: { @setEvalBranchQuata(...); break :val genPrimes(100); }` ?
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<very-mediocre> MajorLag2: thanks
<very-mediocre> Didn't know that was a thing
<very-mediocre> ah, that doesn't work
<very-mediocre> can't use break outside of a loop
<very-mediocre> i could add a dummy loop but then we kind of descend into hacky nonsense
<MajorLag2> you can use labeled breaks this way.
<MajorLag2> I won't know why it wouldn't be working.
<very-mediocre> might have a syntax error
<very-mediocre> hmm
<very-mediocre> yeah, my mistake
<very-mediocre> that works, thanks
<very-mediocre> (put the colon in the wrong place in the break, i've yet to use labeled breaks at all before this)
fjvallarino has joined #zig
very-mediocre has quit [Ping timeout: 252 seconds]
fjvallarino has quit [Ping timeout: 264 seconds]
very-mediocre has joined #zig
nightmared has joined #zig
<Bas_> in tests, do I do foo() catch unreachable; or try foo(); ?
<MajorLag2> Either should fail the test and give you a return trace.
<MajorLag2> Actually, no, I think `unreachable` only gives you the spot where unreachable happened.
fjvallarino has joined #zig
Bas_ has quit [Ping timeout: 252 seconds]
Bas_ has joined #zig
<Bas_> Sorry my pc decided to die. I wanted to ask (or maybe I already did): In tests, do I do foo() catch unreachable; or try foo(); ?
davr0s has joined #zig
fjvallarino has quit [Remote host closed the connection]
fjvallarino has joined #zig
fjvallarino has quit [Ping timeout: 256 seconds]
darithorn has joined #zig
fjvallarino has joined #zig
darithorn has quit [Quit: Leaving]
wilsonk has quit [Read error: Connection reset by peer]
mahmudov has quit [Ping timeout: 256 seconds]
mahmudov has joined #zig
_whitelogger has joined #zig
fjvallarino has quit [Remote host closed the connection]
fjvallarino has joined #zig
andi3 has joined #zig
<andi3> @Bas_ https://irclog.whitequark.org/zig/2018-07-08 so here is the old answer which was that you need to use try
<andi3> a few days ago a question about advise on memory management came up and it just happened that I was talking to a friend about zig and we came to the same question again like I think its pretty clear how zig wants users to acquire memory but what is the strategy for releasing it? I see defer as an option and probably deallocating a whole pool/ arena and doing frees manually but apart from that? thanks
darithorn has joined #zig
<very-mediocre> andi3 i don't think it's fully worked out yet. `defer` is sufficient for a procedural style but it's unclear what OOP features there will be, and if they will be amenable to RAII
SimonNa has joined #zig
<andi3> okay I mean having things in flux is fine by me as well good to know
<very-mediocre> I like the defer pattern, personally
<very-mediocre> i don't see many other options for the procedural style
<very-mediocre> it covers the main footgun of something failing before you can release memory
<andi3> I like defer as well cause I like go as well but go has gc so I just need it for files etc. I'd feel a little lost in a new language just without a destructor I think, I mean I like c but tbh the raw bytes sometimes really should be handled by a compiler rather than my brain+hand
<andi3> actually "even" JBlow has them although advocating against it in the first place, not saying he is the reference but it's just an indication to me
<stratact> I'm afraid to ask this question, but does zig have some form of type inheritance or composition?
<stratact> or would that make the language too complicated
<andi3> I mean composition sure and inheritance I think not but I also think that is pretty much common sense nowadays
<andi3> @very-mediocre if I may give the reference without annoying you here with links https://www.youtube.com/watch?v=8C6zuDDGU2w#t=8m20s about ctor/ dtor just incase someone wants to take a look
<stratact> Composition is nice and I come from a Rust background, but the primary problem is how to implement GUIs with composition, it's not as intuitive compared to inheritance
<stratact> although there is a thing called "Entity Component System" for it
<andi3> https://github.com/ziglang/zig/issues/130#issuecomment-190387636 that is the relevant issue where I think it's safe to say Andrew is aware of it
<stratact> Alright I'll leave a comment about what I said
<very-mediocre> It's anecdotal but I've seen quite a few people itching for some inheritance :)
fjvallarino has quit [Ping timeout: 264 seconds]
<very-mediocre> i'm using it loosely i guess, more like go-style composition
<very-mediocre> feels like some kind of interfaces is inevitable
<very-mediocre> I think it will be possible with #reify to do proper interfaces in userspace
<very-mediocre> @reify*
<very-mediocre> currently it's possible but clunky
<very-mediocre> i'm out, bye
very-mediocre has quit [Quit: Page closed]
<andi3> `feels like some kind of interfaces is inevitable` I just said to a friend if I choose between generics and interfaces of any kind I take interfaces any day
<Bas_> Why?
<Bas_> I've mostly seen interfaces being overused and getting in the way of understanding what is going on.
<Bas_> Not that ducktyping (such as in Python) makes it easy to see what's happening.
<andrewrk> dbandstra, you can create a slice of len 0 like this:
<andrewrk> const slice = ([*]T)(undefined)[0..0];
<andrewrk> this is safe and works at compile time
<andrewrk> I agree with andi3, let's be charitable and non-judgemental with how people spend their time
<andrewrk> I want the zig community and other programming language communities to see each other as friends, and we can help each other
<andrewrk> there's no reason for it to be adversarial
<andrewrk> Bas_, in tests, use try foo() or catch @panic()
<andrewrk> `catch unreachable` will catch test failures in debug mode, but `catch unreachable` will be undefined behavior when testing in release-fast mode. you might get a test failure, might not.
<Bas_> ok
<andrewrk> difference between unreachable and @panic() is that @panic() still panics in release-fast mode
<Bas_> the catch unreachable is what I saw in the zig hashmap tests
<andrewrk> let me have a look
<andrewrk> Bas_, yep. these tests are not idiomatic. I wrote these before `try` was allowed in test blocks, and even before we had @panic
<andrewrk> I'll update them now
<Bas_> hah ok
<andrewrk> I really should grep all of zig source for "catch unreachable" and make sure they're all legit. pretty much every occurence should have a comment explaining why the catch is truly unreachable
<stratact> andrewrk: after you are done updating those, could you look at my github comment about ECS?
<andrewrk> stratact, I'm about to be AFK for a few hours, but I will have a look when I get back
<stratact> cool cool
<andi3> @Bash_ just anytime I want to have a boundary/ API they help me ensure correctness whereas generics are just less typing, although if you have duck typing then interfaces lead to less typing as well which I like but I do not think that would be a goal for zig in itself
<Bas_> Hmm.. yes I can see that it helps clarify the API.
<andi3> I really not sure how zig does this internally so far, maybe I missed it and it works really well already but if so I would be quite surprised but nothing wrong with a surprise ... Go has this principle of having really tiny interfaces for example io.Reader which has just a Read method but in turn you can implement your own in a matter of minutes if not seconds
<andi3> and then plug this into all kinds of existing functionality
<andi3> what I also miss is simmering like this https://en.wikipedia.org/wiki/Ada_(programming_language)#Data_types golang has types that do not auto convert and I brought this up here already and there was not too much excitement from what I can tell but having small custom types that express intent clearly is really valuable IMO and the link goes much further than what go does
<andi3> notice that ada was explicitly meant to be used in systems were bugs are costly like military tech and so this seems pretty aligned with what zig wants to do actually
<MajorLag2> There's actually been some discussion about ranged int types in regard to @reify. I wonder if a more arbitrary check could be supported. Like, if the user could @reify a type and assign a validate() fn to it that would be called in the same way runtime saftey checks are or something.
alexnask_ has quit [Ping timeout: 240 seconds]
<andi3> yes that sounds like something, but the first step is automatic conversion IMO
<andi3> btw. could you tell me reify means? I looked up the issue but the name kind of drives me nuts :D
<MajorLag2> Reify: to make concrete or real. In this context it's the oposite of @typeInfo. You give it a TypeInfo struct you've but together and it will make a type out of it.
<andi3> but why reify? is this some acronym?
<MajorLag2> No, that's an actual word.
<andi3> oh I see that is actually just English
<andi3> looking at this https://github.com/ziglang/zig/issues/383#issuecomment-331461769 makes me kind of happy, I think this could maybe work out but one downside would still be that error messages would probably be not very good, if you have a small language you might still get away with that but ... meh
Ichorio has quit [Ping timeout: 260 seconds]
<Bas_> Looks good.
Bas_ has quit [Ping timeout: 252 seconds]
wilsonk has joined #zig
andi3 has quit [Ping timeout: 252 seconds]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
v1zix has joined #zig
fjvallarino has joined #zig
tyler569 has quit [Quit: Bye!]
quc has quit [Ping timeout: 240 seconds]
v1zix has quit [Ping timeout: 252 seconds]
hoppetosse has quit [Read error: Connection reset by peer]