-- Chuck Liang's First Eiffel Program! -- 4/2/2001, 5:30pm -- To run this program on Hofstra CS Solaris systems, -- First add the following environment bindings (add them to .cshrc): -- setenv PATH /shared/csc/local/SmallEiffel/bin:$PATH -- setenv SmallEiffel /shared/csc/local/SmallEiffel/sys/system.se -- Save this file with as frogprog.e (filename is important) -- type "compile frogprog.e" -- Produced executable is a.out - run it with ./a.out -- the name of the class must be capitalized, but file name is lower case! class FROGPROG creation make -- make is both constructor and "main" feature { NONE } -- components of class (NONE=private, ANY=public) make is -- implementation of constructor/main do io.put_string("The factorial of 6 is "); io.put_integer(factorial(6)); io.put_string("%N"); io.put_string("Without recursion it's still "); io.put_integer(ifact(6)); io.put_string("%N"); end; -- make -- n! function factorial(n: integer) : integer is require n >= 0 do -- braces not needed in if-elseif statements; just put'em in if n<2 then result := 1; else result := n * factorial(n-1); end; -- if end; -- factorial -- non-recursive version: ifact(n: integer) : integer is require n >= 0 local ax : integer; i : integer; -- loop counter do from ax := 1; i := n; -- can't change n directly until i < 2 loop ax := ax * i; i := i-1; end; -- loop result := ax; end; -- ifact end -- end FROGPROG