Programming language experts told Andrew Kelley, the creator of the Zig programming language, that having code which could run at compile time was a really dumb idea. But he went ahead and implemented it anyway. Years later, this has proven to be one of the killer features of Zig. In the Zig world, we call it comptime, from the keyword used to mark code required to run at compile time or variables to be known at compile time.
…
And that is perhaps one of the things you got to constantly remind yourself while using Zig: It is just a form of C on steroids. You are not working with a high-level language. Zig doesn’t give you closures, automatic memory management, inheritance, or even interfaces. It is a bare-bones language, but comptime can often play games with your perception because it is so powerful.
The new self-hosted compiler reduces memory usage 3x compared to the old C++ implementation, also known as the bootstrap compiler.
About package manager
The main goal of this first iteration is to enable simple usage of dependencies to start building a package ecosystem, and to make sure that we can easily package C/C++ projects, not just Zig. The Zig build system can already build C/C++ projects, so we want to make sure we can leverage 40+ years of Open Source work, and not just Zig rewrites.
Zig’s comptime feature is a powerful capability that allows code to be executed at compile-time rather than runtime. Here are some key uses and benefits of comptime in Zig:
Generic programming: Comptime enables flexible generic programming without the need for a separate syntax. Functions can take comptime parameters of type type, allowing for type-based generics.
Compile-time code generation: Comptime allows generating code at compile-time based on input parameters or types, which can lead to more efficient runtime code.
Compile-time code elision: Zig can statically resolve control flow expressions that depend on compile-time known values, allowing for loop unrolling and branch elimination.
Type introspection and manipulation: Comptime enables examining and manipulating types as data, allowing for powerful metaprogramming capabilities.
Optimization: By moving computations to compile-time, runtime performance can be improved as certain operations are pre-computed.
Parsing and processing at compile-time: Complex operations like parsing can be done at compile-time, reducing runtime overhead.
Functional programming patterns: Comptime can be used to implement functional programming concepts like function composition, currying, and partial evaluation.
Custom DSLs (Domain Specific Languages): Comptime allows for creating custom syntax and abstractions within Zig itself.
Compile-time reflection: While Zig doesn’t support runtime reflection, comptime provides powerful compile-time introspection capabilities.
Build-time operations: Comptime blurs the line between build scripts and application code, allowing for sophisticated build-time logic within Zig code itself.
Comptime in Zig is not just a feature but a fundamental part of the language design, permeating many aspects of Zig programming. It offers a unique approach to metaprogramming that is more integrated and consistent compared to macro systems in other languages, while still maintaining a clear separation between compile-time and runtime code
This seems significant. Elm has curring and partial evaluation – very useful.