2018-05-10 17:39:28 +02:00
|
|
|
# 99 Bottles
|
2017-10-16 18:09:39 +02:00
|
|
|
|
|
|
|
Display the text for the *99 Bottles of Beer* song.
|
|
|
|
|
2020-02-21 20:44:33 +01:00
|
|
|
For this, I'm using `s:evaluate` to construct words which
|
|
|
|
display a string when called. This lets the majority of the
|
|
|
|
code read nicely.
|
|
|
|
|
2018-04-25 18:57:28 +02:00
|
|
|
~~~
|
2019-05-13 15:39:44 +02:00
|
|
|
{ 'bottle 'bottles 'of 'beer 'on 'the 'wall 'no 'more
|
|
|
|
'Take 'one 'down, 'pass 'it 'around }
|
|
|
|
[ dup ':%s_'%s_s:put_sp_; s:format s:evaluate ] a:for-each
|
2020-02-21 20:44:33 +01:00
|
|
|
~~~
|
2017-10-16 18:09:39 +02:00
|
|
|
|
2020-02-21 20:44:33 +01:00
|
|
|
Handling of the exact text related to the number of bottles
|
|
|
|
is done with a simple array of functions that get selected
|
|
|
|
based on the number of bottles left. This is done with a
|
|
|
|
very simple filter, where the number of bottles for the
|
|
|
|
purpose of the text is in a set of 2 or more, 1, or none.
|
|
|
|
|
|
|
|
~~~
|
2019-05-13 15:39:44 +02:00
|
|
|
{ [ no more bottles ]
|
|
|
|
[ #1 n:put sp bottle ]
|
|
|
|
[ dup n:put sp bottles ]
|
|
|
|
} 'BOTTLES const
|
2017-10-16 18:09:39 +02:00
|
|
|
|
2019-05-13 15:39:44 +02:00
|
|
|
:number-bottles
|
|
|
|
dup #2 n:min BOTTLES swap a:fetch call ;
|
2020-02-21 20:44:33 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
Thanks to the programatically generated words for the
|
|
|
|
verse text, the main code is nicely readable.
|
2017-10-16 18:09:39 +02:00
|
|
|
|
2020-02-21 20:44:33 +01:00
|
|
|
~~~
|
2017-10-20 03:57:27 +02:00
|
|
|
:display-verse
|
2019-05-13 15:39:44 +02:00
|
|
|
number-bottles of beer on the wall nl
|
|
|
|
number-bottles of beer nl
|
|
|
|
n:dec Take one down, pass it around nl
|
|
|
|
number-bottles of beer on the wall nl ;
|
2017-10-16 18:09:39 +02:00
|
|
|
|
2019-05-13 15:39:44 +02:00
|
|
|
:verses (n-)
|
|
|
|
repeat 0; nl display-verse again ;
|
2017-10-16 18:09:39 +02:00
|
|
|
|
2019-05-13 15:39:44 +02:00
|
|
|
#99 verses
|
2018-04-25 18:57:28 +02:00
|
|
|
~~~
|