Close

99 bottles of beer on the wall

A project log for Argentum programming language

It automatically prevents all memory leaks. It doesn't use GC, so no pauses. It's compiled to machine code. It's crazy safe and fast.

andrey-kalmatskiyAndrey Kalmatskiy 05/28/2023 at 01:210 Comments

There is a famous song:

/*
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
...
1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.

No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
*/

 This song is sometimes used in computer science to compare languages wikipedia.

And even more, there is a dedicated website, that collected 1500+ variations of this program in different languages.

Let's look how this program can be written in Argentum:

using sys {String, log}
using utils { forRange }
using string;

forRange(-99, 1, (count) {
    bottles = (c, n) {
        c == 0 ? "{}
            {n}o more bottles
        " : "{}
            {c} bottle{c != 1 ? "s"}
        "
    };
    log("{}/
        {bottles(-count, "N")} of beer on the wall, {bottles(-count, "n")} of beer.
        {count == 0
            ? "Go to the store and buy some more"
            : "Take one down and pass it around"
        }, {bottles((99 - count) % 100, "n")} of beer on the wall.
    ");
})

 Unlike code in Wikipedia, this solution does the thing:

All in all, despite its young age Argentum succeeded in solving this question in a straightforward and effective way (it compiled to 20k standalone Windows executable).

Discussions