Beers on the wall

From Nemerle Homepage

Life tends usually to be quite a complex being, and to present you with more than one way of achieving your goal. Attitudes to the fact vary considerably among various people; while Windows users concern it a myth, non-Windows fans appreciate the freedom. Whichever is your way, you will have to accept the fact that programming is much more unlike Windows than like it. That is why I hope this little enumeration will help you to find your preferred manner through the jungle of possibilities.

All these programs do exactly the same thing: print on the screen the lyrics of the jolly song called "99 Bottles Of Beer On The Wall". They just do it in various ways. This page is a great collection of SO many more :)

Functional

using System.Console;
 
 
def write_stanza(count){
	| 2 => {WriteLine("2 bottles of beer on the wall, 2 bottles of beer.");
		WriteLine("Take on down and pass it around, 1 bottle of beer on the wall.\n");}
	| 1 => {WriteLine("1 bottle of beer on the wall, 1 bottle of beer.");
		WriteLine("Take on down and pass it around, no more bottles of beer on the wall.\n");}
	| 0 => {WriteLine("No more bottles of beer on the wall, no more bottles of beer.");
		WriteLine("Go to the store and buy some more, 99 bottles of beer on the wall.\n");}
	| _ => {WriteLine($"$count bottles of beer on the wall, $count bottles of beer.");
		WriteLine($"Take on down and pass it around, $(count-1) bottles of beer on the wall.\n");}
}
 
def run_a_couple_of_times(function, times_left){
	function(times_left);
	when (times_left>0) run_a_couple_of_times(function, times_left-1);
}
 
run_a_couple_of_times(write_stanza, 99)

Indentation syntax (Python like)

Note: To compile this example you will need to use the -i flag in the compiler command line.

#pragma indent
using System.Console
 
for (mutable count=99; count>0; count--)
	mutable s="s"
	mutable s2="s"
	mutable noMore= $"$(count-1)"
 
	when (count==2)
		s="s"
		s2=""
		noMore="1"
 
	when (count==1)
		s=""
		s2="s"
		noMore="no more"
 
	WriteLine($"$count bottle$s of beer on the wall, $count bottle$s of beer.")
	WriteLine($"Take one down and pass it around, $noMore bottle$s2 of beer on the wall.\n")
 
WriteLine("No more bottles of beer on the wall, no more bottles of beer.")
WriteLine("Go to the store and buy some more, 99 bottles of beer on the wall.\n")

Properties

using System.Console;
 
 
class Lyrics{
   static mutable text:string;
 
   public static Text:string{
      get{
         def bottles="bottles of beer";
         def wall="on the wall";
         def take="Take one down and pass it around";
 
         for (mutable count=99; count>=0; count--){
            match (count){
               | 2 => {text+= $"2 $bottles $wall, 2 $bottles.\n";
                       text+= $"$take, 1 bottle of beer $wall.\n\n";}
               | 1 => {text+= $"1 bottle of beer $wall, 1 bottle of beer.\n";
                       text+= $"No more $bottles $wall, no more $bottles.\n\n";}
               | 0 => {text+= $"No more $bottles $wall, no more $bottles.\n";
                       text+= $"Go to the store and buy some more, 99 $bottles $wall.\n";}
               | _ => {text+= $"$count $bottles $wall, $count $bottles.\n";
                       text+= $"$take, $(count-1) $bottles $wall.\n\n";}
            }
         }
 
         text;
      }
 
      set { WriteLine("You should not change the lyrics of this beautiful song."); }
   }
}
 
module Bottles{
   Main():void{
      WriteLine(Lyrics.Text);
   }
}
remember
You are very welcome to contribute to the documentation here!