Capture Failure

Stratego -- Strategies for Program Transformation
Success and failure in Stratego allows one to avoid computing with Boolean values all the time. However, sometimes it is necessary to capture the failure (or success) of a strategy and translate it into a term. For example, when performing constant folding? of relational expressions one would like to write
ConstFold :
  |[ i < j ]| -> <lt>(i, j)
However, when the lt fails, the rule fails. What is needed is a little wrapper strategy that turns failure and success into an appropriate term.
ConstFold :
  |[ i < j ]| -> <to-bool(<lt>(i,j))>
where to-bool could be defined as
to-bool(s) =
  if s then
    !|[ true ]|
    !|[ false ]|
that is, when s succeeds return true, otherwise return false.

(Note that these examples use concrete syntax.)

-- EelcoVisser - 17 Jun 2002