4 ms·
> Just please do not make the mistake of believing that it is unique to Zig. Factor brings the best of Forth and Lisp together... What is unique to Zig is that
by gridlockd 6y ago
> Just please do not make the mistake of believing that it is unique to Zig. Factor brings the best of Forth and Lisp together...
What is unique to Zig is that it has these features without bringing together "the best of Forth and Lisp". Sometimes, just being pedestrian is a virtue.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- moomin 6y agoBut comptime is kind of LISP's unique feature, it's just called macros. EDIT: In fairness, Zig's presentation is pretty likeable. You can do a comptime expression pretty trivially in LISP, a comptime parameter or block would require actual effort.
- patrec 6y agoNo. There is a real difference between staged computation of the type that zig has and macros in common lisp, scheme/rust have (so much for lisp's uniqueness BTW). In common lisp you can do completely arbitrary computation at compile- (or read-)time in zig you cannot and crucially you are also not responsible for manually ordering the "stages". E.g. in common lisp you have use eval-when to make sure that stuff is available at the right phase, whereas zig works out the dependency for you.
- creata 6y agoCan you please provide an example of Zig "working out the dependency"? I'm struggling to make sense of your comment.
- patrec 6y agoI could write a concrete example that will work in zig and fail in common lisp, but maybe this link is enough? https://ziglang.org/#Order-independent-top-level-declarations https://ziglang.org/#Order-independent-top-level-declaration...
- creata 6y agoOh, so is the point that in Zig, functions with comptime parameters are more or less identical to regular functions in that regard?
- dnautics 6y agoExactly. You can also use non-comptime functions in comptime, if it avoids certain types of stateful behaviour.
- dinglejungle 6y agoAn example of this in the Zig math tests, where it tests calling the same function at both comptime and runtime: https://github.com/ziglang/zig/blob/33c4ad7f3a79aad5d7ea481ac98b42dc9f469076/lib/std/math.zig#L517-L527 https://github.com/ziglang/zig/blob/33c4ad7f3a79aad5d7ea481a...
- patrec 6y agoIn common-lisp you could do something equivalent, but you'd have to wrap the definitions you want to be able at both compile and and run time in eval-when.