Digest #22 2017-10-26
As pointed out by Harold firstname.lastname@example.org, "printable character" is not defined in the standard, and there are definitions (Wikipedia) that include BL among the printable characters. However, in the '<char>' syntax, <char> was not intended to be BL; moreover, ' ' produces the xt of ' on all tested systems (as intended). So we should fix this bug by replacing
<char> represents any printable character.
<char> represents any non-blank non-control character.
Both Forth-2012 and Forth-94 specify ASCII as character encoding, so we know that the value of BL is #32 (or $20). The rationale claims that BL is the only way to get this value, but it is wrong.
What is your use case for this? Could you show us an example?
We discussed this at the standards meeting, but do not have an answer for this proposal yet. Anyway, here is my personal answer:
It is a common problem to have a global variable that you want to restore on exiting a word, whether the exit is regular, or through THROW. This problem exists not just for system variables like STATE or BASE, but also for application variables. The general approach that I recommend is to have wrappers around the code that changes the variables. The wrapper catches any exception coming through, restores the old value of the variable, and then THROWs the exception (if any) on. For STATE, this can be done as follows:
: state! ( f -- ) if ] else postpone [ then ; : state-wrapper ( xt -- ) state @ >r catch r> state! throw ; \ usage example s" ] non-existent-word" ' evaluate ' state-wrapper catch .
My main use case was trying to handle any errors that may occur when including another file, e.g.
S" somefile.4th" ' INCLUDED CATCH ...
This code could be interpreted or compiled, and of course inside somefile.4th the STATE can change arbitrarily prior to a THROW. So anything following CATCH would only work as intended if STATE had not changed. Your example is certainly one way to work around this, but it requires every use of CATCH to be wrapped. In my opinion, if CATCH does not restore STATE, it falls short of satisfying this from the THROW Rationale: "If THROW is executed with a non zero argument, the effect is as if the corresponding CATCH had returned it." The application variables are certainly the application's responsibility, but system variables should be the system's.
If an otherwise standard system chose to restore STATE and BASE as part of the CATCH semantics, would this still be a standard system?
Indeed, so we could move BL to core ext to make it optional.
There's no need for a size constrained system to contain a word that's trivially replaced by a literal with known value.