Tue Sep 25 19:44:24 CEST 2007
Something that's really handy in scheme is a short-circuiting 'or'.
i'm in need for something like that to define interactive word
semantics: try executable words first, then try variable names, then
try constants (or later macros). In scheme this is easy because
variables are referenced multiple times, in CAT this is awkward due to
explicit copying/restoring of the argument stack.
Some backtracking formulation would be nice, but generic backtracking
is overkill. It also requires explicit handling of the continuation
object. Escaping continuations work fine here, and they can be stored
in a dynamic parameter, so no explicit manipulation of continuation
objects is necessary.
With 'check' being a word that aborts the current branch if the top of
the stack is false, using the quasiquote (see next post) this is
`(,(foo check do something check more stuff)
,(bar check do something else)
,(in case everything fails))
In a compositional language, escape continuation (EC) based
backtracking might take the role of a conditional expression because
it's often easier to go ahead and backtrack on failure than to
perform a number of tests/asserts ahead of time which might CONSUME
your arguments, so you need to SAVE them first. An EC can be used to
restore the contents of the stack before taking another branch.
The disadvantage of course is that words that use 'check' are only
legal within an 'attempt' context, and are not referentially
transparent. I guess this is ok.. same as using catch/throw.
I do feel a bit like a cowboy now.. What about distinguishing 'bad'
exceptions from 'good' ones? Using exceptions in CAT has always been
awkward, but the 'attempts' syntax here seems nice.