real language

Bookmarking Digg Diigo DZone Earthlink Google
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language ML

Author:Jong-Won Choi
Score: (3.02 in 107 votes)
(* ML version of 99 bottles of beer                               *)
(*   - Using pattern of functions parameters                      *)
(*     and Recursion(like other functional programming langauges) *)

(* Written by Jong-Won Choi(           *)
(*                                                     Nov 13, 95 *)

fun NinetyNineBottlesOfBeer(0) =
  print("\n No more bottles of beer on the wall\n")
| NinetyNineBottlesOfBeer(1) = 
   (print("\n 1 bottle of beer on the wall, 1 bottle of beer.");
    print("\n Take one down and pass it around.");
| NinetyNineBottlesOfBeer(NumberOfBottles:int) =
   (print("\n "); print(NumberOfBottles);
    print(" bottle of beer on the wall, ");
    print(" bottle of beer.");
    print("\n Take one down and pass it around.");
    NinetyNineBottlesOfBeer(NumberOfBottles - 1));

Download Source | Write Comment

Alternative Versions


>>  Shaun said on 10/11/07 00:02:08

Shaun Yeah, it needs a call to NinetyNineBottlesOfBeer(99) to actually display it, but as far as just a function to display any amount this one is pretty good. The recursive power of ML is great.

>>  Paul said on 11/19/07 13:32:35

Paul Sadly, the plurals are not correct.

>>  Maxwell K said on 10/22/08 16:32:27

Maxwell K This is the best example I've seen on the site.

Great work!

>>  Omundu said on 05/12/09 07:59:55

Omundu Liked it so much that I spent some time tweaking it to work with SML/NJ v110.67. print was just not liking ints

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!




Security Code: