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 Icon

(Version that spells out numbers)

Date:02/13/06
Author:Frank J. Lhota
URL:n/a
Comments:1
Info:http://www.cs.arizona.edu/icon/
Score: (2.67 in 15 votes)
# Frank J. Lhota
link numbers   # uning spell procedure

#################################################################
#
# Returns a phrase indicating the beer inventory of the wall
#
#################################################################
procedure inventory(beercount)
  static lc, uc
  initial  {
    lc := string (&lcase)
    uc := string (&ucase)
    }

  return case beercount of  {
    0       : "No more bottles"
    1       : "One bottle"
    default : {
      # Capitalize the result of spell
      spell(beercount) ? (
        map (move (1), lc, uc) || tab (0) || " bottles" )
      }
    } || " of beer on the wall"
end

#################################################################
#
# Writes out the verse for beercount number of beers. Returns the
# number of beers on the wall at the end of the verse
#
#################################################################
procedure write_verse (beercount)
  local inv

  write (inv := inventory(beercount), ",")
  write (inv, ".")
  if beercount > 0 then {
    write ("Take one down and pass it around,")
    write (inventory(beercount -:= 1), ".")
    }
  else {
    write ("Go to the store and buy some more,")
    write (inventory(beercount := 99), ".")
    }
  write()

  return beercount
end

procedure main()
  local beercount
  static wall_capacity
  initial wall_capacity := 99

  # Start with wall fully stocked;
  # Keep writing verses until the wall is restocked
  beercount := wall_capacity
  until (beercount := write_verse (beercount)) = wall_capacity
  return
end

Download Source | Write Comment

Alternative Versions

Comments

>>  Chris said on 04/19/06 08:35:56

Chris There are a few object-oriented derivatives for the Icon language:

Idol: Discontinued, but serves as the basis for Unicon, its successor
Unicon: http://unicon.sf.net/

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: