Software Transformation Systems

Only a couple so far, hopefully many more to come. We've assumed a C++ style commenting convention for the TIL language to make these more readable.

**factors.til**

Note: This program uses an unspecified assumption (that the "write" statement outputs a full line) -- JRC

// Find all factors of a given input number - J.R. Cordy August 2005 var n; write "Input n please"; read n; write "The factors of n are"; var f; f := 2; while n != 1 do while (n / f) * f = n do write f; n := n / f; end f := f + 1; end

**factorial.til**

Note: this program, from the Stratego manual, has an error (declaring x) and uses a couple of unspecified assumptions (that the "write" statement does not output a full line, and that "\n" is allowed and outputs a newline) -- JRC

// TIL program computing the factorial - Eelco Visser var n; read n; var x; var fact; fact := 1; for x := 1 to n do fact := x * fact; end write "factorial of "; write n; write " is "; write fact; write "\n";

-- JamesCordy - 22 Aug 2005 (revised JamesCordy - 30 Aug 2005)