One Program in Three Programming Languages

-> Home page -> Favourites flag

99 Bottles on the Wall
99 bottles of beer on the wall,
99 bottles of beer.
Take one down, pass it around,
98 bottles of beer on the wall.
...
2 bottles of beer on the wall,
2 bottles of beer.
Take one down, pass it around,
1 bottle of beer on the wall.
1 bottle of beer on the wall,
1 bottle of beer.
Take one down, pass it around,
No more bottles of beer on the wall!

This song surprisingly serves as a test-bed for different languages. Well, not too serious test-bed - but quite interesting! Take your favourite language and try to implement the song.

Although it is not too difficult, your language (or you) must cope with three different subtasks:

  • cycling, iteration (99, ..., 2, 1)
  • branching ('bottles' versus 'bottle')
  • sequence (you are not going to print all the text at once, aren't you)

If you are really interested, visit web page devoted entirely to '99 bottles'. The page contains implementations of the song in almost 1500 different programming languages and variations. This group of languages contains:

  • languages commonly regarded as programming languages, e.g. C, C++, C#
  • not so general programming languages, e.g. C language preprocessor, Postscript, SAOL (music synthesis)
  • programs which do not play the role of programming languages, e.g. procmail, sed (unix stream editor)

A '99 bottles' song serves as a test-bed for my implementations. The aim is to illustrate some basic features of three programming languages, namely Common Lisp, Prolog, and Clips. In order to reduce the amount of text to be displayed, we use a reduced version of the song:

...
6 bottles of beer on the wall. Take one down, and pass it around.
5 bottles of beer on the wall. Take one down, and pass it around.
4 bottles of beer on the wall. Take one down, and pass it around.
3 bottles of beer on the wall. Take one down, and pass it around.
2 bottles of beer on the wall. Take one down, and pass it around.
1 bottle of beer on the wall. Take one down, and pass it around.
Now, they are all gone.
while the number of bottles is expected as a parameter when programs are called. It is expected as one number from < 0, 1, 2, .... > - no error handling is implemented in order to keep implementations as simple as possible.

Common Lisp
bottles.lsp
Prolog
bottles.pl
Clips
bottles.clp

Copyright © MM
Last updated 6.12.2004