]> gitweb.factorcode.org Git - factor.git/blob - extra/99-bottles/99-bottles.factor
e05df79744ad654ec678036f36521969a6e28037
[factor.git] / extra / 99-bottles / 99-bottles.factor
1 ! Copyright (C) 2011 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: ascii combinators combinators.smart io kernel math
4 math.parser math.ranges sequences splitting ;
5 IN: 99-bottles
6
7 : bottles ( n -- number string )
8     [ dup 0 > [ number>string ] [ drop "No more" ] if ]
9     [ 1 = not "bottles" "bottle" ? ] bi ;
10
11 : verse ( n -- )
12     [
13         {
14             [ bottles "of beer on the wall," ]
15             [ bottles "of beer.\nTake one down, pass it around," ]
16             [ 1 - bottles [ >lower ] dip "of beer on the wall." ]
17         } cleave
18     ] output>array join-words print nl ;
19
20 : last-verse ( -- )
21     "No more bottles of beer on the wall, no more bottles of beer." print
22     "Go to the store and buy some more, 99 bottles of beer on the wall." print ;
23
24 : 99-bottles ( -- )
25     99 1 [a..b] [ verse ] each last-verse ;
26
27 MAIN: 99-bottles