4 ms·
Zig Programming Language Blurs the Line Between Compile-Time and Run-Time
- FrancoDiaz 10y agoI like what I'm seeing, but a suggesting regarding shortened keywords. Just go ahead and change compTime to compileTime. I don't see 3 extra characters saving much and makes it less readable. Most modern editors will autocomplete anyway.
- FrancoDiaz 10y agoI'm the last person to talk about type theory, but on the max function example: fn max(comptime T: type, a: T, b: T) -> T { if (a > b) a else b } fn letsTryToPassARuntimeType(condition: bool) { const result = max( if (condition) f32 else u64, 1234, 5678); } Then we get this result from the compiler: ./test.zig:6:9: error: unable to evaluate constant expression if (condition) f32 else u64, ^ Couldn't the compiler infer some kind of union type. You don't know the type at runtime, but f32 or u64 is a legit comparision type.