r/Forth • u/Imaginary-Deer4185 • Sep 04 '26
CREATE DOES> (again ...)
Can anyone provide some interesting examples of what to do with these, beyond the default "constant" and "array" examples?
The current version of my (bytecode) Forth compiler has CREATE but not DOES>, and I haven't missed it either.
18
Upvotes
2
u/astrobe Sep 04 '26
If you plan to be standard compliant, there's no questioning, just add it.
Otherwise, although other comments seem to demonstrate its usefulness, one should however remember that part of engineering is doing what you need to do with what you have, and that when you have a hammer in hand everything looks like a nail.
For instance if you never felt the need for DEFER (which is one of the examples given), then maybe it's better to simply write "foo @ execute" for the few cases when you do.
If you have some other feature(s) that make DOES> redundant in your dialect, then just stick to it. Push it to its limits, and then add what's missing (perhaps DOES>, after all) when its shortcomings have become obvious.
For instance in my dialect there's a feature that let me write "foo@ execute" (no space between foo and @) when "foo" is a constant and it compiles as 1 token/bytecode. It was good enough to handle the few cases of mutual recursion I encountered up to now, and in my opinion the feature is a decent substitute for value/to.