Add FAIL native for raising an error or error-spec #87
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The FAIL native takes the place of DO'ing an error to raise it, and
is also able to take a STRING! or a BLOCK!. The string is sent to
MAKE ERROR! directly, while blocks are processed in a new kind of
"error creation dialect". The dialect evaluates a WORD! as long as
it does not evaluate to a function, and also will evaluate parens:
...this would behave equivalently to what has been written as:
Limiting types is to faciliate the dialect becoming more expressive.
It may use SET-WORD!, TAG!, and other choices to cue the fields
and formatting template structure for the error object being returned
to TRAP. Hence those types are available for future expansion. In
the meantime, the PAREN!'s general-purpose-escape will allow
for any substitution that FORM REDUCE might otherwise achieve.
It removes a commented out prior placeholder for a FAIL-like native
that was named "CAUSE". That word may make sense when paired
directly with something like a variable named
error
...but as aconvenience routine that might be used with (for instance) a string it
doesn't communicate that an error has occurred and that execution
will be interrupted. (RAISE was rejected for similar reasons.)
This is planned as the replacement for DO's handling of errors. So
calling DO on an ERROR! will now still raise an error, but not the one
you asked for...rather an error directing the user to the use of FAIL.
Similarly, THROW directs users who try and pass errors to use FAIL
(as it would be a common misconception for people from other
languages to think that THROW is what you are supposed to use).
While a refinement was considered to allow throwing errors, the
rarity of the operation and the existence of workarounds (e.g. putting
the error in a block) makes it seem better to leave it. Should throwing
an ERROR! turn out to be actually common, this can be reconsidered
and a refinement named.