Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Frink

(Demonstrates units of measure in Frink)

Date:05/17/11
Author:Alan Eliasen
URL:http://futureboy.us/
Comments:0
Info:http://futureboy.us/frinkdocs/
Score: (3.00 in 26 votes)
/* Frink tracks units of measure through all calculations.  It has a large library of built-in units
of measure, including volume.  The following program prints out the remaining volume of beer
(assuming we start with 99 bottles of beer, each containing 12 fluid ounces) in different random
units of volume, never repeating a unit. */

units = array[units[volume]]
showApproximations[false]

for n = 99 to 0 step -1
{
   unit = units.removeRandom[]
   str = getBottleString[n, unit]
   
   println[str + " of beer on the wall, " + lc[str] + "."]

   if (n == 0)
      println["Go to the store and buy some more, 99 bottles of beer on the wall."]
   else
      println["Take one down and pass it around, " + lc[getBottleString[n-1, unit]] + " on the
wall.\n"]
}

getBottleString[n, unit] := format[n*12 floz, "${unit}", 6] + "s"

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Shorter alternative by Frink's authorAlan Eliasen04/12/070

Comments

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!

Name:

eMail:

URL:

Security Code:
  
Comment: