[Prev][Next][Index][Thread]

Re: simple method dispatch question



On 11/10/00 12:15 PM, the artist formerly known as Michael T. Richter,
(mtr@ottawa.com), issued a press release stating:

> What use are singletons?

For another simple example of the use of singletons see:

<http://www.ionet.net/~timtroyr/funhouse/beer/beer_d_h.html#dylan>

Which has this code:


// Dylan version of 99 Bottles of Beer
// programmer: Jim Studt jim@federated.com

define method enumerate( count == 1 ) "1 bottle" end method enumerate;
define method enumerate( count == 0 ) "no more bottles" end method
enumerate;
define method enumerate( count :: <integer> )
  format-to-string("%d bottles", count);
end method enumerate;

define method reference( count == 1) "it" end method reference;
define method reference( count :: <integer>) "one" end method reference;

define method main (argv0, #rest noise)
  for ( i from 99 to 1 by -1)
    format( *standard-output*, "%s of beer on the wall, %s of beer.\n",
       enumerate(i), enumerate(i));
    format( *standard-output*,
       "  Take %s down, pass it around, %s of beer on the wall.\n",
       reference(i), enumerate( i - 1));
  end for;
end method main;



The rest of that site is a pretty interesting intro to some otherwise
unfamiliar languages as well.
-- 

Raffael Cavallaro, Ph.D.
raffael@mediaone.net



References: