real language

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

Language Unicon

Author:Christian Meurin
Score: (3.01 in 118 votes)
# Unicon is a "unified extended dialect" of the Icon programming language. 
# It introduces modern features such as object orientation and such.
# Unicon is the successor of Idol, an earlier attempt at Icon OOP.
# The current source code has been left alone for nearly 2 years, so
# I'm not sure if this is still in development.

package bottlesofbeer

$define BEERMAX 99
$define LOWBEER 1
$define NOBEER 0

class BeerSong()
   method start_chugging()
      local beercount

      beercount := BEERMAX;

      while beercount >= NOBEER do {
        # this could be slightly mistyped, but I'm not sure
        if beercount not LOWBEER then {
           write (beercount, " bottles of beer on the wall,\n");
           write (beercount, " bottles of beer.\n");
        } else {
           write ("One more bottle of beer on the wall,\n");
           write ("One more bottle of beer.\n");

        write ("Take one down, pass it around,\n");

        case beercount of {
           0       : write ("No more bottles of beer on the wall.\n")
           1       : write ("One more bottle of beer on the wall.\n")
           default : write (beercount, " more bottles of beer on the wall.\n")

      write ("Get out of my bar yeh drunk low life!\n");

Download Source | Write Comment

Alternative Versions


>>  Christian Meurin said on 04/22/06 21:20:56

Christian Meurin Slight fix:

while beercount >= LOWBEER do {

I entered the NOBEER constant, oops!

>>  Steve Wampler said on 01/28/09 17:20:33

Steve Wampler There are a few minor problems with the above code - including
the fact that once the syntax error is fixed and a main procedure
is added, it's an infinite loop. Here's a variant that works
(he claims), although it also uses a few more esoteric features
of Unicon:

procedure main(args)
numBeers := integer(args[1]) | 99

class BeerSong()
method start_chugging(beerMax)
local beerCount

every beerCount := beerMax to 1 by -1 do {
write( (beerCount = 1, "One bottle";)| (beerCount || " bottles";),
" of beer on the wall,";)
write( (beerCount = 1, "One bottle";)| (beerCount || " bottles";),
" of beer.";)

write("Take one down, pass it around,";)
write(case beerCount of {
1 : "No more bottles"
2 : "One more bottle"
default : (beerCount-1)||" more bottles"
}," of beer on the wall.\n";)

>>  Steve Wampler said on 01/28/09 17:25:35

Steve Wampler Sigh. Obviously I don't know the format for embedding code...
Quick test (sorry, I don't see any instructions):
# this is a comment

>>  khalida said on 06/16/09 10:39:11


>>  Steve Wampler said on 01/12/10 17:26:29

Steve Wampler No, Unicon is not the same as ADL. Unicon is a successor to Icon which,
in turn, is a successor to SNOBOL4.

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: