Digest #347 2026-09-13
Contributions
referenceImplementation - Udate reference implementation for `ALSO`
The original reference implementation does not handle the case where the search order is empty.
: ALSO ( -- )
GET-ORDER DUP 0= IF -50 THROW THEN
OVER SWAP 1+ SET-ORDER
;
NB: the search order overflow should be checked in set-order.
See also: the section 16.4.1.2 Ambiguous conditions, Table 9.1, and contribution #447.
Replies
proposal - New words: latest-name and latest-name-in
If I have the case of a data type needs checking and throwing if it's not correct, I usually create a word that throws on error:
: ?nt ( nt|0 -- nt ) \ throws on nt=0
dup 0= -80 and throw ;
Then the cases where there needs to be a check can have that check, and it's a short word to insert, e.g.
: immediate ( -- ) immediate-mask latest-name ?nt >flags or! ;
requestClarification - What should happen when calling ALSO when the search order is empty?
I don't understand what would happen if the search order is empty.
This is an implicit ambiguous condition: it should obviously have been declared, but was likely overlooked.
The Table 9.1 contains a throw code -50 search-order underflow.
: ?nt ( nt|0 -- nt ) \ throws on nt=0 dup 0= -80 and throw ;
In that case, what is the error message?
Note that we already have ?found ( x1\0 -- x1 ^^ 0 -- never ).
Then the cases where there needs to be a check can have that check, and it's a short word to insert,
This approach is useful when you sometimes need to handle 0 locally, while in other cases you need to throw an exception.
For latest-name, there is almost no use cases where you need to handle 0 locally (please, provide examples if you have). And in very rare cases where you need to handle 0 locally, I suggest to use another word.
To avoid similarity in names when the stack effect is not similar, I suggest to change the naming as follows:
last-name-in ( wid -- nt|0 ) \ It is needed as a basic API method
last-name ( -- nt|0 ) \ It is very optional, since it is almost not needed in practice
latest-name ( -- nt ) \ It is used in most practical use cases
Is it acceptable for you?