24 ms·
Immediate words don’t cover the “while maintaining consistent behavior (i.e., semantics) across phases” of the definition given, do they? I think normal forth
by Someone 2y ago
Immediate words don’t cover the “while maintaining consistent behavior (i.e., semantics) across phases” of the definition given, do they?
I think normal forth words are way closer to that. They (1) normally just do whatever their definition implies, but inside a colon definition, they (1) compile code that does whatever their definition implies.
They do miss C++ constexpr (https://en.cppreference.com/w/cpp/language/constexpr https://en.cppreference.com/w/cpp/language/constexpr). I haven’t read Zig docs, but that seems highly similar to Zig’s comptime to me.
(1) technically, it’s not “they” doing that themselves but whatever code processes them.
- kragen 2y agoyeah, the forth feature that actually does this is not immediate words in general, but the two immediate words [ and ], which allow you to do arbitrary ad hoc computations at compile time instead of at run time but also you can just put the code you would have put between the [ ] delimiter words into an immediate word, and call it where you would have put the [ ] block. the effect is not exactly the same but it has semantics slightly more consistent with the usual semantics because your immediate word is in fact compiled just like non-immediate words are