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) =
    s; ![[ true ]] <+ ![[ false ]]
that is, when s succeeds return true, otherwise return false.

(Note that these examples use concrete syntax.)

-- EelcoVisser - 17 Jun 2002

Revision: r1.1 - 17 Jun 2002 - 19:11 - EelcoVisser
Stratego > StrategoGlossary > CaptureFailure
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback