Recent submissions

Comment · 2 months ago

  Location: Tbilisi, Georgia
  Remote: Yes
  Willing to relocate: Yes
  Technologies: Rust, Nix
  Résumé/CV: https://alurm.github.io/cv.pdf
  Email: [email protected]
Software engineer, open source maintainer. Systems programming, developer tools, Unix.
Comment · 4 months ago
Yeah, I've added macros `vec_len` and `vec_ptr` (or, enums, actually), which help somewhat.

`arr[3]` should be flagged by the compiler it is known to the compiler that you're operating on an array.

You can pass `arr` as `&arr` to functions, then compiler will know the length of the array since the type would be `T ()[2]`.

And you can then use it like this:

  void f(int *(*ints)[2]) {
      for (size_t i = 0; i < (size_t)vec_len[*ints]; i++) printf("f: %d\n", vec_ptr[*ints][i]);
  }
Curiously, this is a rare case where the "inverted" `a[b]` requires less typing compared to `(b)[a]`.

A compiler will not be able to flag `vec_len[ints]` though, which is unfortunate.

Comment · 4 months ago
Thank you! I implemented this pattern initially about a year ago, but decided to write about it now. Since you liked it, it wasn't for nothing. :)
Comment · 4 months ago
You're right, I added some more clarity in the README.

Interestingly, I think my approach will work fine on CHERI, since the pointer is never dereferenced, but I didn't test this. But yeah, there are some architectures where it would fail.

Comment · 4 months ago
Good point! Added `vec_ptr[vec]` and `vec_len[vec]` helpers to mitigate this somewhat.
Comment · 4 months ago
Thanks for mentioning it, I've heard about stb, but this time around I actually looked at the code. Their approach is very nice.
Comment · 7 months ago
Making a strict subset of some existing language (Go) be a "better C" is quite an interesting idea compared to others (D, Zig, Hare, C3, D, ...), haven't seen it elsewhere. No new syntax. And Go seems to be a pretty good choice for this. Not sure if it's gonna fly though.
Comment · 1 year ago
Yes, but you can generate JSON with other tools easily. home.md describes how you can do it with Nix, but just as easily you can use Cue or something else.

Edit: mentioned this in the README explicitly. Thanks!

Comment · 1 year ago
Yeah, in general (a bit of a tangent), ideas from Plan 9 are really powerful. For example, the Acme text editor exposes it's API as a file system (it's represented via Unix sockets in plan9port, but FUSE is available as well there). It's easy to write scripts to manipulate the editor, and quite fun.
Comment · 1 year ago
Well, if you're generating JSON with Nix, you don't have to put everything inside of one file. It would be a better idea to split it up into multiple. You can also use builtins.readFile for reading config files which don't have to be generated in a complex manner. It's up to you to choose, I just kept everything inside of one file since it makes for a simpler example.

Edit: I have updated the documentation to mention this explicitly, thanks!

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton