Remix.run Logo
messe 13 hours ago

It has stringly typed macros. It's not comparable to Zig's comptime, even if it calls it comptime:

    fn main() {
        comptime {
            var N = 20;
            var fib: long[20];
            fib[0] = (long)0;
            fib[1] = (long)1;
            for var i=2; i<N; i+=1 {
                fib[i] = fib[i-1] + fib[i-2];
            }

            printf("// Generated Fibonacci Sequence\n");
            printf("var fibs: int[%d] = [", N);
            for var i=0; i<N; i+=1 {
                printf("%ld", fib[i]);
                if (i < N-1) printf(", ");
            }
            printf("];\n");
        }

        print "Compile-time generated Fibonacci sequence:\n";
        for i in 0..20 {
            print f"fib[{i}] = {fibs[i]}\n";
        }
    }
It just literally outputs characters, not even tokens like rust's macros, into the compiler's view of the current source file. It has no access to type information, as Zig's does, and can't really be used for any sort of reflection as far as I can tell.

The Zig equivalent of the above comptime block just be:

    const fibs = comptime blk: {
        var f: [20]u64 = undefined;
        f[0] = 0;
        f[1] = 1;
        for (2..f.len) |i| {
            f[i] = f[i-1] + f[i-2];
        }
        break :blk f; 
    };
Notice that there's no code generation step, the value is passed seamlessly from compile time to runtime code.