News for hackers. Stuff that matters.
Re:How I Built Zig-SQLite by SkeuomorphicBee on Friday May 27, 2022 @08:57AM (#31529066)
In case anyone else is unfamiliar with Zig syntax and wondering: in Zig the .{ "somevalue"} represents an anonymous list literal [1], and .{.somename = "somevalue"} is an anonymous struct literal [2].

(A bit off topic rant, but Zig documentation is quite bad, it took me a lot more effort that it should to discover the facts above.)

[1] https://ziglang.org/documentation/master/#Anonymous-List-Lit...

[2] https://ziglang.org/documentation/master/#Anonymous-Struct-L...

Re:How I Built Zig-SQLite by jmull on Friday May 27, 2022 @12:04PM (#31531186)
I thought the docs were quite good.

I used "ziglearn" to understand ("chapter 1" and "chapter 2" have tons of foundational stuff): https://ziglearn.org/chapter-1/

I used the language reference for the details: https://ziglang.org/documentation/master/#Introduction

I agree the standard library docs aren't useful (unless something changed a lot in the last six months)... it seemed always better to just search and read the standard library source directly.

Re:How I Built Zig-SQLite by messe on Friday May 27, 2022 @12:40PM (#31531603)
> I agree the standard library docs aren't useful (unless something changed a lot in the last six months)... it seemed always better to just search and read the standard library source directly.

They're automatically generated. As I understand it they've been holding off on improving them until they have the self hosted compiler working, as it will be easier at that point.

Re:How I Built Zig-SQLite by throwawaymaths on Friday May 27, 2022 @12:43PM (#31531654)
To be fair it's really hard to "search" for tuples and anyonymous structs and get an understanding from "reading the stdlib". It's also enough of a departure from C (but not obviously readable like types on the left) to warrant some sort of big red flag in the lang docs... Understanding this tripped me up a bit
Re:How I Built Zig-SQLite by LAC-Tech on Friday May 27, 2022 @10:29AM (#31530065)
Zig is still not 1.0. I can forgive its lack of docs at this point, especially how surprisingly readable the std lib is.
Re:How I Built Zig-SQLite by akira2501 on Friday May 27, 2022 @01:59PM (#31532667)
I'm not wild about the new trend of languages of making a bunch of syntax dependent on a single small sigil. It gives me a strong feeling of Perl's historical "eclecticness" and I feel like I'm putting more effort into correctly reading the program back into my mind than I should ideally have to.
Re:How I Built Zig-SQLite by kzrdude on Friday May 27, 2022 @03:39PM (#31533946)
I'm wondering what the point of the period is here, could it be done without it?
Re:How I Built Zig-SQLite by throwawaymaths on Friday May 27, 2022 @08:32PM (#31536487)
I think it allows the parser to be context-free since otherwise it is tricky to distinguish it from a code block. They could have picked a different sigil, but I think . was landed on because it had the fewest semantic conflicts with other concepts in the language (for example % is used to denote modular arithmetic)
Re:How I Built Zig-SQLite by alpaca128 on Friday May 27, 2022 @04:14PM (#31534364)
I don't know why, but this is a part of the language's syntax, for example when matching a union type each named variant also has that period. Same with the argument for print statements (`print("{s}", .{var})`).
Re:How I Built Zig-SQLite by kzrdude on Friday May 27, 2022 @04:21PM (#31534442)
aha, seems like they use the list argument to print instead of having varargs functions then?
Re:How I Built Zig-SQLite by bo0O0od on Friday May 27, 2022 @10:32PM (#31537097)
In zig code blocks are expressions and can appear in a lot of places, e.g. on the RHS of an assignment. Probably possible to not need the dot but considerably more complicated.
Re:How I Built Zig-SQLite by metadat on Friday May 27, 2022 @07:39PM (#31536173)
Is `.{"somevalue"}` a string array of length 1?

The dot seems quite superfluous and quite the silly quirk (in an unintuitive way). How do Python and Go get by without such a mystery sigil?

Re:How I Built Zig-SQLite by throwawaymaths on Friday May 27, 2022 @08:29PM (#31536473)
It's a tuple of length one with an array of u8. A tuple is an anonymous struct with special fields that are numerical, note that also tuples can be accessed by index syntax. Some distinction from empty braces is necessary because "naked" empty braces are for code blocks. It's only unintuitive to you because it's different and you're not used to it yet.