99 bottles of beer: Difference between revisions

(→‎{{header|Pike}}: alternate version)
Line 4,212:
ENDLOOP
</lang>
 
=={{header|TXR}}==
 
{{works with|seq|7.1 (GNU coreutils)}}
 
Here we scan the output of the seq command counting down from 99 to -1, one number per line. The <code>@(trailer)</code> directive allows us to match a trailing context within a text stream without consuming it. So we have access to N-1 without advancing over it, allowing it to be captured as N in the next iteration of <code>@(collect)</code>.
Iterating down to -1 ensures that the 0 case has a next number, otherwise the match would fail and that case would vaporize. That is what happens to -1.
 
<lang txr>@(next `!seq 99 -1 -1`)
@(collect)
@number
@ (trailer)
@number_less_1
@ (cases)
@ (bind number "1")
@ (output)
1 bottle of beer one the wall
1 bottle of beer
@ (end)
@ (or)
@ (output)
@number bottles of beer one the wall
@number bottles of beer
@ (end)
@ (end)
@ (cases)
@ (bind number "0")
@ (output)
Go to the store and get some more,
99 bottles of beer on the wall!
@ (end)
@ (or)
@ (output)
Take one down and pass it around
@number_less_1 bottles of beer on the wall
 
@ (end)
@ (end)
@(end)</lang>
 
=={{header|UNIX Shell}}==
Anonymous user