Language Clean
(Pure, lazy, functional)
Date: | 04/19/07 |
Author: | Peter Achten |
URL: | http://cs.ru.nl/P.Achten/ |
Comments: | 0 |
Info: | http://clean.cs.ru.nl/ |
Score: | (2.94 in 17 votes) |
module bottles99 // Compile with Clean 2.2 (http://clean.cs.ru.nl/) with Project:Project Options:No Return Type import StdEnv Start :: *World -> *World Start world # (stdio,world) = stdio world # (_, world) = fclose (fwrites (foldr (+) "" [sing nr \\ nr<-[99,98..0]]) stdio) world = world the_wall = " on the wall" sing :: Int -> String sing n = capitalize (bottles n) + the_wall + ", " + bottles n + ".\n" + if (n==0) ("Go to the store and buy some more, " + bottles 99 + the_wall + ".\n") ("Take one down and pass it around, " + bottles (n-1) + the_wall + ".\n\n") bottles 0 = "no more bottles of beer" bottles n = toString n + " bottle" + if (n==1) "" "s" + " of beer" capitalize :: String -> String capitalize str = toString (cap str.[0]) + str%(1,size str-1) cap :: Char -> Char cap c = if (isMember c ['a'..'z']) (hd [['A'..'Z']!!i \\ c`<-['a'..'z'] & i<-[0..] | c`==c]) c instance + String where (+) a b = a +++ b // shorthand notation + instead of +++
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