←back to thread

Things Zig comptime won't do

(matklad.github.io)
458 points JadedBlueEyes | 2 comments | | HN request time: 0.001s | source
Show context
karmakaze ◴[] No.43745047[source]
> Zig’s comptime feature is most famous for what it can do: generics!, conditional compilation!, subtyping!, serialization!, ORM! That’s fascinating, but, to be fair, there’s a bunch of languages with quite powerful compile time evaluation capabilities that can do equivalent things.

I'm curious what are these other languages that can do these things? I read HN regularly but don't recall them. Or maybe that's including things like Java's annotation processing which is so clunky that I wouldn't classify them to be equivalent.

replies(3): >>43745080 #>>43745506 #>>43745688 #
awestroke ◴[] No.43745080[source]
Rust, D, Nim, Crystal, Julia
replies(3): >>43745176 #>>43745645 #>>43746241 #
elcritch ◴[] No.43745645[source]
Definitely, you can do most of those things in Nim without macros using templates and compile time stuff. It’s preferable to macros when possible. Julia has fantastic compile time abilities as well.

It’s beautiful to implement an incredibly fast serde in like 10 lines without requiring other devs to annotate their packages.

I wouldn’t include Rust on that list if we’re speaking of compile time and compile time type abilities.

Last time I tried it Rust’s const expression system is pretty limited. Rust’s macro system likewise is also very weak.

Primarily you can only get type info by directly passing the type definition to a macro, which is how derive and all work.

replies(2): >>43746822 #>>43746836 #
int_19h ◴[] No.43746836[source]
> Rust’s macro system likewise is also very weak.

How so? Rust procedural macros operate on token stream level while being able to tap into the parser, so I struggle to think of what they can't do, aside from limitations on the syntax of the macro.

replies(3): >>43747055 #>>43747359 #>>43749005 #
forrestthewoods ◴[] No.43747359{4}[source]
Rust macros are a mutant foreign language.

A much much better system would be one that lets you write vanilla Rust code to manipulate either the token stream or the parsed AST.

replies(1): >>43748134 #
1. dwattttt ◴[] No.43748134{5}[source]
...? Proc macros _are_ vanilla Rust code written to manipulate a token stream.
replies(1): >>43756111 #
2. forrestthewoods ◴[] No.43756111[source]
You’re right. I should have said I want vanilla Rust code for vanilla macros and I want to manipulate the AST not token streams.

Token manipulation code is frequently full of syn! macro hell. So even token manipulation is only kind of normal Rust code.