Digest #90 2020-01-11
Contributions
: FACTORIAL ( +n1 -- +n2 ) DUP 2 < IF DROP 1 EXIT THEN DUP 1- FACTORIAL * ; After the execution of the ":" the word FACTORIAL is defined in the vocabulary and available for FIND. Even as incomplete definition, nothing prevents to compile the call to itself. Why special word is needed?
Replies
As I can see, a license is not mentioned anywhere in the standard.
Usually, reference implementations are licensed under some permissive license or even dedicated to the public domain. Particularly, the reference implementations that are the result of standardization processes are often dedicated to the public domain (see Wikipedia).
In any case, we may assume there is no any licensing fees.
@ruv: Your implementation sketch is not complete enough to be sure what the plan is.
I published a proof of concept, a working example that can be tested on a standard Forth system, see at GitHub.
Looking at the behaviour of S" in SwiftForth (it behaves as a STATE-smart rather than dual word), I don't expect SwiftForth to change even if you remove the ambiguous condition; unless a customer complains, but they apparently have not about S".
My proposal does not affect S"
word. Applying POSTPONE
to S"
was never ambiguous. So, behavior of POSTPONE S"
is already non standard in SwiftForth. I just show a simple way how to fix this issue, and also make POSTPONE
proper working for other words with minimal effort.
I agree that it is reasonable to wait until the proper implementation will be sufficiently common. OTOH, there is a sense to take into account only those Forth systems in which POSTPONE
correctly works for all words except TO
, IS
and ACTION-OF
(that are only affected by my proposal). Since if POSTPONE
incorrectly works for some other words in a Forth system, changing the ambiguous condition regarding these three words does not change the compliance status of this Forth system. Don't sure that we know even a few such Forth systems.
See the specification of : :
The current definition shall not be findable in the dictionary until it is ended
So your FACTORIAL does not work in standard Forth. That's why Forth has RECURSE.
Why are colon definitions only visible later? 1) If you make an error, resulting in an incomplete definition, this protects you from calling it. 2) You can define words with the same name, and extended behaviour that calls a previous word with the same name.