Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
Name:
Anonymous2008-04-25 16:21
1 to(100) each("x") {
case
{ x %(3) ==(0); } { writeLine("Fizz"); }
{ x %(5) ==(0); } { writeLine("Buzz"); }
{ x %(3 *(5)) ==(0); } { writeLine("FizzBuzz"); }
unless { writeLine(x); };
};
Here is my contribution, written in my own programming language, a derivative of Io (and indirectly, Smalltalk) that stole Ruby's syntax for blocks and also forgoes Io's syntactic sugar for infix expressions.
* Number#to constructs a range object.
* Range#each iterates over the range and accepts a single argument, the name to which the number in the range will be bound in the corresponding block.
* Object#case accepts mutually exclusive (predicate, action) block pairs and returns whether any of the predicates succeeded (making Bool#unless act as a sort of else clause).
Semicolon statement delimiters are needed (unfortunately) so that message send chains may be broken into several lines.
The interpreter, of course, is written in HASKELL.