Language F#
Date: | 03/10/06 |
Author: | Christoph Reiche |
URL: | n/a |
Comments: | 0 |
Info: | http://research.microsoft.com/fsharp/fsharp.aspx |
Score: | (3.00 in 2 votes) |
(* ninetyninebottlesofbeer.fs *) open System open System.IO open System.Windows.Forms let f = new Form() do f.Width <- 500; f.Height <- 420; f.Visible <- true; f.TopMost <- true; f.FormBorderStyle <- System.Windows.Forms.FormBorderStyle.FixedSingle; f.Text <- "99 bottles of beer presented in F#" let rb = new RichTextBox() do f.Controls.Add(rb); rb.Size <- new System.Drawing.Size(480, 350); rb.Location <- new System.Drawing.Point(5, 5) let btnClose = new Button() do btnClose.Location <- new System.Drawing.Point(408, 360); btnClose.Text <- "Close"; btnClose.add_Click (new EventHandler(fun _ _ -> f.Close())); f.Controls.Add(btnClose) let x = ref 0 let strPlural = ref "s" let strSong = ref "" let CreateSong() = ( for i = 99 downto 0 do if (i = 0) then ( strSong := !strSong ^ "\r\nNo more bottles of beer on the wall, no more bottles of beer." ^ "\r\nGo to the store and buy some more, 99 bottles of beer on the wall."; ) else ( x := i - 1; if (i = 1) then ( strPlural := "" ); strSong := !strSong ^ "\r\n" ^ string_of_int i ^ " bottle" ^ !strPlural ^ " of beer on the wall, " ^ string_of_int i ^ " bottle" ^ !strPlural ^ " of beer." ^"\r\nTake one down and pass it around, "; if (!x = 1) then ( strSong := !strSong ^ string_of_int !x ^ " bottle " ) else if (!x = 0) then ( strSong := !strSong ^ " no more bottles " ) else ( strSong := !strSong ^ string_of_int !x ^ " bottles " ); strSong := !strSong ^ " of beer on the wall.\r\n"; ) done; ) do CreateSong(); rb.Text <- !strSong [<STAThread>] do Application.Run(f)
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
Using list comprehension | Jörn Rönnow | 02/01/09 | 3 | |
Cleaner still | Don Syme | 12/07/06 | 0 | |
Recursive implementation | Alec Zorab | 07/04/09 | 0 | |
Tail Recursion Call | Simon Kang | 06/22/09 | 0 | |
lists and lambda's | Kyle Eppley | 05/04/10 | 0 |
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!
Comments