If Then Else

Stratego -- Strategies for Program Transformation

Syntax

"if" Strategy "then" Strategy "else" Strategy "end" -> Strategy

Description

<if s1 then s2 else s3 end> t

If s1 succeeds then strategy s2 is applied. If s1 fails, then s3 is applied.

The result of condition is ignored. If the condition succeeds, then the result is

<s2> t

If the condition fails, then the result is

<s3> t

Formatting

The if then else construct is usally formatted in the following way:

if s1 then
  s2
else
  s3
end

Implementation

The if-then-else construct is sugar for a guarded left-choice. The strategy

if s1 then s2 else s3 end
translates into

where(s1) < s2 + s3