Sather ![]() |
http://www.gnu.org/software/sather |
similar languages: | Blue Eiffel | |
Description: | Sather is an Eiffel-like language. It features:
|
Factorial | Michael Neumann |
class MAIN is fac(n : INT) : INT is if n <= 1 then return 1; else return n * fac(n-1); end end; main is #OUT + fac(6) + "\n"; end; end; |
Calculates the factorial. Results
720 . |
Hello World | Michael Neumann |
class MAIN is main is #OUT + "Hello World\n"; end; -- main end; -- class MAIN |
Prints "Hello World" onto the
screen. |
Squares (1) | Michael Neumann |
class MAIN is squares : STR is r ::= ""; -- implicit type loop r := r + (1.upto!(10) ^ 2) + " " end; return r; end; main is #OUT + squares + "\n"; end; end; |
Outputs the squares from 1 to
10. |
Squares (2) | Michael Neumann |
class MAIN is -- squares! is an iterator yielding the squares of the -- numbers from "from" to "to". squares!(once from : INT, once to : INT) : INT is loop i ::= from.upto!(to); yield i * i end end; main is loop #OUT + squares!(1, 10) + " " end; #OUT + "\n"; end; end; |
Outputs the squares from 1 to
10. |
Squares (3) | Michael Neumann |
class MAIN is squares is a : ARRAY{INT} := |1,2,3,4,5,6,7,8,9,10| ; b : ROUT{INT}:INT := bind(_.pow(2)); -- a closure a.map(b); loop #OUT + a.elt! + " " end; end; main is squares; #OUT + "\n"; end; end; |
Outputs the squares from 1 to
10. |