Re:What Makes the Zig Programming Language Unique?
by Ferret7446 on Wednesday October 05, 2022 @10:43PM
(#33103726)
What is generating code at compile time, if not code running at compile time?
[ Parent
| on HN ]
Re:What Makes the Zig Programming Language Unique?
by anonymoushn on Wednesday October 05, 2022 @10:57PM
(#33103826)
If one wishes to be pedantic, constexpr is a C++-like language for generating C++ values at compile time and templates are a quite different language for doing the same thing (and some other things). The pitch of the comptime feature is that you can do all of the things you would do with templates and constexpr (and more things due to some limitations being relaxed and type introspection existing) in the language that is similar to the language you use for runtime code. You don't have to do anything in a weird metalanguage.
Re:What Makes the Zig Programming Language Unique?
by gpderetta on Thursday October 06, 2022 @07:51AM
(#33107039)
C++ has been trying to get compile time introspection and synthesis into the language for a while. There is a proposal going slowly through standardization, but it is not yet know when it will be ready (I believe it missed 2 or more release trains already).
Circle, mentioned elsewhere, is a C++ dialect with fully working compile time metaprogramming.
Re:What Makes the Zig Programming Language Unique?
by rurban on Thursday October 06, 2022 @10:03AM
(#33108278)
C++ has only half of a fully working compile time metaprogramming.
constexpr are limited, consteval, would be the full part, but is usually an error.
And the error handling is even only 10% working. clang is fine, gcc is broken for years.
Re:What Makes the Zig Programming Language Unique?
by duped on Wednesday October 05, 2022 @11:12PM
(#33103929)
The big thing is the macro language is restricted to generating additional code when it's evaluated whereas compile time expressions are more about reducing expressions into literals.
Re:What Makes the Zig Programming Language Unique?
by kazinator on Thursday October 06, 2022 @02:27AM
(#33105053)
Not any code that you can program yourself. It's a bunch of template deduction/instantiation rules specified in the C++ standard, baked into the compiler, which you can steer only to the extent that you can grab the template declaration syntax by whatever horns it it is trying to gore you with.