Paste: 99 bottles; help!
Author: | mnestic |
Mode: | factor |
Date: | Tue, 13 Jan 2009 19:47:51 |
Plain Text |
: bottle
[
[
[
[ # " bottles of beer on the wall,\n" % ]
[ # " bottles of beer.\n" % ] bi
] keep
"Take one down, pass it around,\n" %
1- # " bottles of beer on the wall\n" %
] " " make print
] ;
: last-verse
"Go to the store and buy some more,"
"No more bottles beer on the wall!" [ print ] bi@ ;
: bottles
1 [a,b] bottle each last-verse ;
Author: | Arne Ehrlich |
Mode: | factor |
Date: | Thu, 9 Apr 2009 08:11:37 |
Plain Text |
USING: kernel math math.ranges io sequences math.parser make arrays combinators unicode.case ;
IN: bottles
PREDICATE: no < integer 0 <= ;
PREDICATE: one < integer 1 = ;
PREDICATE: some < integer 1 > ;
GENERIC: bottle
M: no bottle drop "No more bottles" ;
M: one bottle drop "One bottle" ;
M: some bottle [ # " bottles" % ] "" make ;
: bob [ bottle % " of beer" % ] "" make ;
: bobw [ bob % " on the wall.\n" % ] "" make ;
: list-bottles [ bobw >lower ] [ bob ] bi [ % ", " % % ] "" make ;
: take-one dup 1 <
[ drop 99 "Go to the store and buy some more, " ]
[ 1- "Take one down, pass it around, " ] if swap bobw >lower 2array concat ;
: verse [ list-bottles ] [ take-one ] bi 2array concat ;
: song 0 [a,b] [ verse print ] each ;
New Annotation