top | item 47126537

(no title)

astrobe_ | 7 days ago

You're welcome. Actually, Forth doesn't have forward declarations as a "direct" feature, but it has what I would call "function values", which can be used like functions and changed almost like variables [1]. This is used for all kind of things, including forward declarations because otherwise some recursive algorithms would be very painful to write if not impossible. It's still not ideal because it is an unnecessary indirection.

It could have message passing by doing what I described earlier, like you would do in C by having a switch-case function that dispatches messages to dedicated routines. It would even be easier because there's no type checking, and more specifically no function signatures.

That's something one could do in specific cases where it is advantageous, but otherwise I would say it is "anti-idiomatic" for Forth. In particular, although Forth has no problem with variadic functions and multiple returns, including variable number of results [2], it is discouraged.

Forth is generally trying hard to push things from run-time to compile-time, and Chuck Moore was very pleased to find a way to push things from compile-time to edit-time with ColorForth [3]: the user, by switching the colors of tokens, tells the system what it should do with it: compile it, or execute it right now, or do nothing because it is comment.

[1] https://forth-standard.org/standard/core/DEFER

[2] https://forth-standard.org/standard/core/qDUP

[3] https://colorforth.github.io/cf.htm

discuss

order

No comments yet.