Zig’s “greedy” compile time evaluation of expressions (and even functions, if requested) seems pretty unique to me.
Question One: Does anyone know other languages with this feature.
NOTE: I’m aware that optimizing compilers will often do this, but I don’t consider that a language-level feature the way comptime is in Zig.
Question Two: How would you classify Zig’s metaprogramming capabilities?
It’s really interesting because Zig achieves metaprogramming without a separate metalanguage or dialect. At the same time, it’s not homoiconic in the sense that you can’t manipulate code as data.
It has reflection, but only at compile time (that’s correct to say, isn’t it?).
It has generics without really having to provide much in the way of explicit language-level support for generics (
anytype being an obvious exception, and the builtin
@Type, and probably other things I don’t know about).
The closest thing I’ve heard of (but never used, I’m not that old) are the procedural macros in PL/I’s preprocessor which is PL/I code written in the same language but explicitly run at compile time:
Macros in the PL/I language are written in a subset of PL/I itself…
When a % token is encountered the following compile time statement is executed… Thus a compile time variable
PIcould be declared, activated, and assigned using
%PI='3.14159265'. Subsequent occurrences of
PIwould be replaced by
Which is clearly the same idea, but it’s just for a small subset of the full PL/I language.
Related Wikipedia topics: