USING: combinators combinators.smart io kernel math math.parser math.ranges sequences ascii ; IN: 99-bottles : bottles ( n -- number string ) [ [ 0 > ] [ number>string ] [ "No more" ] smart-if* ] [ 1 = "bottle" "bottles" ? ] bi ; : verse ( n -- ) [ [ bottles "of beer on the wall," ] [ bottles "of beer.\nTake one down, pass it around," ] [ 1 - bottles [ >lower ] dip "of beer on the wall." ] tri ] output>array " " join print nl ; : last-verse ( -- ) "No more bottles of beer on the wall, no more bottles of beer." print "Go to the store and buy some more, 99 bottles of beer on the wall." print ; : 99-bottles ( -- ) 99 1 [a,b] [ verse ] each last-verse ; MAIN: 99-bottles