ChanServ changed the topic of #zig to: zig programming language | | be excellent to each other | channel logs:
DJoubert has quit [Client Quit]
<benjikun> how do I cast i8 to usize?
<benjikun> is that a nono
<benjikun> oh, nevermind, @intCast(usize, yadayada)
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
aquiandres has joined #zig
aquiandres has quit [Read error: Connection reset by peer]
<oats> why does zig not allow variable shadowing?
<oats> /home/oats/projects/zig/hellos/terminal.zig:52:21: error: redeclaration of variable 'column'
<oats> for (line) |column, x| {
<oats> `column` is defined in a scope enclosing that loop, but has nothing to do with the loop
<hryx> My guess is either to keep the language simpler or to prevent bugs... or both
<oats> fair enough :)
<hryx> I've definitely caused some fun/havoc in Go (which allows shadowing) by accidentally using `x :=` instead of `x =` and vice versa
<shachaf> The "x, err :=" where you want to assign to x but shadow err is the best.
<shachaf> Er, no the other way around.
<benjikun> Have any of you used nim?
<hryx> that's my favorite!
<benjikun> I'm kinda attached to nim atm
<shachaf> I've played Nim, does that count?
<benjikun> no but I've seen that game everytime I've googled 'nim'
<benjikun> lol
<oats> what's a nim?
<benjikun> a language that compiles to C/C++/objC/JS
<benjikun> the original name was 'Nimrod' but it was shortened to 'Nim'
<benjikun> I'm making a draft for a starting wikipedia page for Zig, what should I put under "influenced by"?
<hryx> C, at least
<benjikun> I'm thinking C/C++ for sure
<benjikun> isn't `defer` a thing from go originally?
<hryx> not sure, but that's where I first saw it
<benjikun> what paradigms should I include?
<benjikun> imperative, structured?
<oats> ooh, zig has defer :D
<jfondren> defer I thought was from Jai, Jon Blow's language
<benjikun> possibly
<benjikun> I like that guy
<shachaf> I first saw defer in Go but it's pretty strange that it's function-scoped rather than block-scoped.
<benjikun> zig first appeared in 2017, right?
<benjikun> anyone know?
<benjikun> I'll just go with that, because that's when 0.1.0 came
<benjikun> ooh, thanks
<benjikun> I'll change it to that
tolitius has joined #zig
tolitius has quit [Ping timeout: 240 seconds]
_whitelogger has joined #zig
m4ge123 has quit [Ping timeout: 252 seconds]
raoof has joined #zig
Summertime has quit [Quit: Sunsetting.]
Summertime has joined #zig
raoof has quit [Quit: Page closed]
_whitelogger has joined #zig
_whitelogger has joined #zig
MajorLag has quit [Read error: Connection reset by peer]
MajorLag has joined #zig
davr0s has joined #zig
Ronja has joined #zig
<meowray> I've got a PR in my project (ccls). Doesn't provide such prebuilt tarball?
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
xeqtr has joined #zig
jreut has joined #zig
<jreut> What sorts of things are fit for inclusion in Zig's standard library?
<jreut> I've been writing a CSV parser for a project. Is that something you want andrewrk?
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
iamthad has joined #zig
<iamthad> Is it possible to make a struct type support array initialization?
xeqtr has quit [Ping timeout: 272 seconds]
Hejsil has joined #zig
<Hejsil> jreut, as far as I know most things are welcome in std, but will later be removed once we approach 1.0.0.
<Hejsil> iamthad, You want this? const A = struct.{a: u8, b: f32}; const a = A.{4, 2.3}; ?
<iamthad> Yeah, that's what I'm looking for.
<Hejsil> I don't think Zig is gonna have this. It's to easy to make mistakes
<iamthad> Gotcha. It doesn't save that much typing compared to making an init function anyway.
<iamthad> Is it possible to test that a particular expression fails to compile / gives a compileError?
<Ronja> what's the situation with strings and unicode in zig?
<Hejsil> iamthad, no and I think it's a rejected proposal. I can try to find the issue
<Hejsil> Ronja, "strings" are just arrays/slices of bytes ([]u8). Special unicode handling like iteration and decoding is handled in userland
<iamthad> I see some CompileErrorContext stuff in the tests directory but that looks pretty complex.
<Hejsil> That's just a layer that invokes the compiler on a string, and tests if the compiler succeeds or fails
<Hejsil> Only useful for tests really
<Hejsil> (the code that does this that is)
<iamthad> Gotcha, thanks
<Hejsil> iamthad, can't find the issue, but it has been discussed
<iamthad> Thanks for checking. I'll keep an eye on it.
<Hejsil> Hmm, I thought there where more things discussed here
<Hejsil> Maybe some of the debate on this is in other issues
<Hejsil> It can be hard to find the correct "meta programming" proposal sometimes
<iamthad> I see. My intended usage was for testing that a given error is caught at compile time, rather than the more versatile usage there
<Hejsil> Aaah, right. I think there has been some talk here too. Let me look further
steveno has joined #zig
<iamthad> Thanks, that's the sort of thing I'm looking for. Seems like a good capability
Jenz has joined #zig
porky11 has joined #zig
Jenz has quit [Quit: leaving]
<jreut> Hejsil, thanks for the information!
<Hejsil> For now, the more code we have in std (with good tests) the more we stress the language :)
<Ronja> Hejsil: does the standard library (plan to) support things like "get character count" for say utf-8 encoded strings? or methods like to_upper() for non-ascii characters?
<Hejsil> Idk
<jreut> :) glad to hear it. it's been great having a builtin test facility in a systems language
davr0s has joined #zig
<Ronja> I'm tempted to comment that not seemlessly supporting unicode strings in a brand new language quite unappealing for very large swaths of the world in 2018
<Ronja> I'm talking about things like slicing, truncating, to_uppering etc. of strings internally encoded in utf-8, preferrably
<bheads> Thats really a std lib problem
<bheads> They put auto decoding for utf-8 in D, and now they are trying to remove it
<euantor> All of the above can be easily implemented in the standard library - either by wrapping a C lib or by writing it fresh
<euantor> Remmeber that Zig isn't 1.0 and something not being in the standard library yet doesn't mean that it'll never be
<Ronja> yes I am aware
<euantor> I would imagine the only reasons for it not already being there are: nobody has needed it enough to spend the time; it's fairly boring work
<bheads> The language is still in flux, so there is no point in polishing the stdlib yet. Things are added as people need it.
<Ronja> but can something like const str = "åäö"; const slice = str[1..2]; assert(mem.eql(u8, slice, "äö")); really be a std lib thing? I've never written a programming language, though, so...
<bheads> You need a function to decode that string
<Ronja> why?
<bheads> having the language do it would hide the implmentation
<bheads> utf decoding is not cheap
<Ronja> you say that like it's a bad thing
<bheads> not saying that
<bheads> Zig is avoiding "magic" code
<Ronja> I get that
<bheads> besides what if my array is just bytes
<Hejsil> If you decode your "åäö" into a []u32, then your slicing would work
<bheads> I dont want that to get decoded
<Ronja> I guess really my point is that "strings == byte arrays" is an easy thing to do but it makes the language very very inconvenient for many many people
<bheads> no strings != bytes
<Ronja> a separate unicode-aware string type that does decoding, character counting, slicing and uppercasing for me is really nice
<bheads> sure, that can be in user land
<bheads> you dont need that in that language
<Hejsil> It's probably best if it isn't
<Hejsil> At least in Zig
<bheads> They added it in D, and its a mess
<Ronja> I guess, but can the user land implementation be as nice as str[n..m] or will become something like utf8_str_slice(strptr, n, m)
<Hejsil> Ronja, as I said. You could decode into a []u32, and then it would work
<Hejsil> But it depends on what you need from you string
<bheads> also in your string slice example what does n and m mean? codepoints or indexs?
<Hejsil> There is probably gonna be something like an UniString, and then you can call str.slice(n,m)
<Hejsil> In the context of strings, it's probably codepoints
<bheads> it should be
<Ronja> bheads: codepoints. I don't know why I would every want anything else in string contexts.
<Ronja> ever*
<bheads> that way mixing arrays and strings are bad
<bheads> to easy to mix up codepoints and index
<Hejsil> Well, if you have precomputed indexs that are safe to slice with on a string, then you wouldn't wonna pay the cost of slicing with codepoints
<Ronja> bheads: that's exactly my point
<bheads> so slicing syntax would be a bad choice
<Ronja> what do you mean? python and rust can do slicing on codepoint counts just fine
<bheads> yeah but now slicing means two different things
<Ronja> I guess, technically
<Hejsil> Well, if your string is UTF8 encoded, then your slicing operation ins O(N)
<Ronja> yse
<bheads> no its not
<bheads> you need to decode to find the index bounds
<euantor> Zig's string is more like Rust's CString
<Hejsil> Enligten me
<Hejsil> And how is that not O(N)?
<bheads> I read it as O(1) my bad
<Hejsil> euantor, ye that's about right
<bheads> zig doesn't have strings, just arrays
<bheads> strings have data and an encoding
<bheads> we are just hardcoding in the encoding, normally utf-8
Hejsil has quit [Quit: Page closed]
Zaab1t has joined #zig
<oats> Is an aim of Zig to replace C for use in microprocessors and embedded platforms, too?
<benjikun> I think the potential to maintain that possibility is an aim
<benjikun> anyone can correct me if I'm wrong on that
<benjikun> I'm working on this page for zig, if any of you guys wanna help add references or material, there ya go
<benjikun> I think adding specific "description" and "history" sections would be nice
<oats> yeah, I most pages on programming languages seem to have a "design" section
<oats> s/I//
<benjikun> true
<oats> it should probably have subsections on syntax, memory management, types, etc
<oats> although I'd be hestitant to describe the syntax on the wikipedia page when it's in such flux :P
<benjikun> yeah, I'm also pretty new to zig and I don't want to make any mistakes on the page heh
<oats> benjikun: you know what, I think that's pretty good as is
<oats> though I'd be tempted to remove the first "hello world" example
<oats> and just show the one using warn()
<benjikun> hmmm
<benjikun> should I submit it for review?
<oats> how about that hello world, I think it kinda hints at how namespacing works a bit better
<benjikun> will do
<oats> and how about a factorial function? :D
<oats> moment
<benjikun> How about this one?
<oats> that's great :D
<oats> I didn't know about comptime int
<oats> does that mean that the compiler's actually doing the calculation, and the result is hardcoded in the binary?
<benjikun> I believe so
<oats> maybe if you use that, attach a short explanation of the comptime things used, since that's an important feature of zig
<benjikun> true, will do
<benjikun> added
return0e has quit [Read error: Connection reset by peer]
<oats> looks pretty good
<benjikun> ty
<benjikun> I wish this IRC were more active
<benjikun> this channel, I mean
<benjikun> s/were/was/ I don't really know, english, man
SimonNa has quit [Remote host closed the connection]
SimonNa has joined #zig
<oats> eh, zig's not very big
<oats> kinda expected
<oats> it's also the middle of a work day in the States
wootehfoot has joined #zig
<benjikun> yeah, ik
<benjikun> just would be nice
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
DutchGh0st has joined #zig
<DutchGh0st> can you force the size and alignment of a struct?
return0e has joined #zig
DutchGh0st has quit [Quit: - A hand crafted IRC client]
davr0s has joined #zig
darithorn has joined #zig
Zaab1t has quit [Ping timeout: 244 seconds]
Zaab1t has joined #zig
moo has joined #zig
wootehfoot has quit [Ping timeout: 268 seconds]
DutchGh0st has joined #zig
<DutchGh0st> In rust I have a function that returns an _mm128i struct, which is a simd struct...
<DutchGh0st> I import that into zig, but set the return type to a 'c_int'
<DutchGh0st> I then call the function, cast the reference to a Zig struct that has an array of 16 bytes internally to match the size..., is it safe to then derefence it?
<DutchGh0st> *call the function, take a reference to the return value, and cast it
Zaab1t has quit [Quit: bye bye friends]
Zaab1t has joined #zig
<MajorLag> oddly enough, there doesn't seem to be a way to declare a struct, or a struct field, with an alignment. Best I can come up with is having an init fn that has an aligned return: `pub fn init() align(16) T`
<DutchGh0st> const _mm128i align(16) = struct { <-- ?
<DutchGh0st> const _mm128i align(16) = struct { data: [16]u8, } , doesn't that have an align of 16, and a size of 16?
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<DutchGh0st> but thats cheating a bit
<DutchGh0st> I have not had a *correct* output on just a single standing array
<benjikun> oats: Well they are criticizing the lack of independent sources on the wikipedia article
<benjikun> There are only two real "articles" on zig :/
<benjikun> These wikipedia people are the most passive aggressive people I've ever met
steveno has quit [Quit: Leaving]
wilsonk has quit [Read error: Connection reset by peer]
wilsonk has joined #zig
<MajorLag> yeah, you can create an instance of a struct with an alignment, but can't create the type with an inherent alignment.
<MajorLag> er... or maybe you can and I just had the syntax wrong despite several variations
<benjikun> Is stdlib documentation planned for anytime soon?
<MajorLag> I don't believe so
<benjikun> dang
<MajorLag> `const _mm128i align(16) = struct {` has an alignment of 8 in my test, but the compiler didn't bark about it so that's probably a bug.
<MajorLag> No, wait, I think that means "align this variable (_mm128i) at 16", but since _mm128i is a type, that's effectively meaningless. So there isn't a way to say "this type is aligned to X", at least not that I can fidn.
<DutchGh0st> well, there should I think?
<DutchGh0st> In rust we have `#[repr(align(N))]`, where N is the alignment
<DutchGh0st> but maybe I just have to wait untill simd stuff comes into Zig :)
<DutchGh0st> it was just a test if it was possible currently with FFI, basically is not really
DutchGh0st has quit [Quit: - A hand crafted IRC client]
<MajorLag> DutchGh0st, this version of your paste should be less hacky at least:
<MajorLag> I haven't tested it
<benjikun> He left
Zaab1t has quit [Quit: bye bye friends]
<MajorLag> I know, but IIRC he looks at the logs
<benjikun> oh, I see
<benjikun> sorry
<benjikun> If I'm doing a "@cInclude("X11/Xlib.h");" and I want to do something like "const display = c.XOpenDisplay(0x0);", how would I do that?
<benjikun> It's complaining about not being able to implicitly cast to '[*]const u8'
<MajorLag> in this case probably `const display = c.XOpenDisplay(@intToPtr([*]const u8, 0));`. Ideally it would be `const display = c.XOpenDisplay(null);`, but from the error it looks like zig didn't translate `char *` as nullable.
<benjikun> oh okay, I see tysm
<benjikun> well, actually using 'null' lets it compile now
<MajorLag> maybe it did correctly translate it and the error only reported the non-nullable portion of the type.
<benjikun> hm
<benjikun> Xlib uses a #define for Mod1Mask and some other stuff (`#define AllMods (ShiftMask|LockMask|ControlMask| \`)
<benjikun> Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)
<benjikun> How would I utilize those?
<benjikun> I can't just do `c.Mod1Mask`
<benjikun> oh, I guess I can just use the integer counterpart that I find from the X11 stuff
moo has quit [Read error: Connection reset by peer]
<jfondren> you should be able to do c.Mod1Mask; you can do that for many other X11 constants
<jfondren> it looks like zig's C translation doesn't understand constants defined with bitwise operators
<jfondren> that's probably an oversight.
<benjikun> ah
<jfondren> $ grep KeyPress /usr/include/X11/X.h
<jfondren> #define KeyPressMask (1L<<0)
<jfondren> #define KeyPress 2
<jfondren> $ zig translate-c /usr/include/X11/X.h|grep KeyPress
<jfondren> pub const KeyPress = 2;
<benjikun> good idea
<benjikun> ty
porky11 has quit [Quit: Leaving]