Language Oberon
(object-oriented version)
| Date: | 04/20/05 |
| Author: | Michael Griebling |
| URL: | n/a |
| Comments: | 0 |
| Info: | n/a |
| Score: |
MODULE BeerSong;
(* An object-oriented beer song in Oberon-2 *)
(* Contributed by Michael Griebling (mgriebling@bix.com) *)
IMPORT O:=Out;
TYPE
WallObject* = RECORD beer-: SHORTINT END;
VAR
BeerWall : WallObject;
PROCEDURE (VAR wall: WallObject) LineEmUp*;
BEGIN wall.beer := 99
END LineEmUp;
PROCEDURE (VAR wall: WallObject) PassOneAround*;
BEGIN DEC(wall.beer)
END PassOneAround;
PROCEDURE (VAR wall: WallObject) HasMoreBeer* () : BOOLEAN;
BEGIN RETURN wall.beer > 0
END HasMoreBeer;
PROCEDURE SingOf(beer: SHORTINT);
BEGIN
IF beer = 0 THEN O.String("No more") ELSE O.Int(beer, 1) END;
O.String(" bottle"); IF beer#1 THEN O.Char("s") END; O.String(" of beer")
END SingOf;
PROCEDURE (VAR wall: WallObject) SingVerse*;
BEGIN
SingOf(wall.beer); O.String(" on the wall, "); SingOf(wall.beer); O.Ln;
O.String("Take one down and pass it around,"); O.Ln;
SingOf(wall.beer-1); O.String(" on the wall."); O.Ln; O.Ln
END SingVerse;
BEGIN
BeerWall.LineEmUp;
WHILE BeerWall.HasMoreBeer() DO BeerWall.SingVerse; BeerWall.PassOneAround END
END BeerSong.
Download Source | Write Comment
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