% $Id: SumFromTo.oz,v 1.1 2007/10/22 03:48:52 leavens Exp leavens $ declare % Return the sum of the numbers from I to J, inclusive. % Gauss's formula is faster, but this demonstrates the basic form of % tail recursion to achieve iterative behavior. fun {SumFromTo I J} fun {SumFromToIter JnR} J#R=JnR in if I > J then R else {SumFromToIter J-1#R+J} end end in {SumFromToIter J#0} end