Language Wrapl
| Date: | 12/30/06 |
| Author: | Raja Mukherji |
| URL: | http://wrapl.sf.net |
| Comments: | 0 |
| Info: | http://wrapl.sf.net |
| Score: |
mod bottles;
imp std.io.terminal use Out;
def tens <- [
"", "Twenty", "Thirty", "Forty", "Fifty",
"Sixty", "Seventy", "Eighty", "Ninety"
];
def ones <- [
"one", "two", "three", "four", "five",
"six", "seven", "eight", "nine"
];
def small <- [
"One", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen",
"Sixteen", "Seventeen", "Eighteen", "Nineteen"
];
def words(N) (
-- If 0 < N < 20 then we use the simple number small[N].
-- If N > 20 then small[N] fails so we try a compound number.
-- ones[N % 10] will fail for N a multiple of 10 so we just use the tens string in this case.
-- If N = 0 then tens[N / 10] will fail so we get "No more".
ret (small[N] | (tens[N / 10] + ((" " + ones[N % 10]) | "")) | "No more") +
-- If N = 1 then " bottle of beer" otherwise " bottles of beer".
(N = 1 => " bottle of beer" // " bottles of beer")
);
var I <- 99;
var Words <- words(I);
rep (
Out:write(Words + " on the wall,\n");
Out:write(Words + ",\n");
Out:write("You take one down and pass it around,\n");
Words <- words(I <- $ - 1);
Out:write(Words + " on the wall.\n");
Out:write("\n");
until I = 0;
);
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments