Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Zig Programming Language Blurs the Line Between Compile-Time and Run-Time (andrewkelley.me)
4 points by AndyKelley on Jan 30, 2017 | hide | past | favorite | 2 comments


I'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.


I 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.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: