Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!mcvax!enea!ttds!duvan!zap From: zap@duvan.UUCP (Svante Lindahl) Newsgroups: net.lang.c Subject: Re: A good use of a bad feature Message-ID: <812@duvan.UUCP> Date: Sat, 10-May-86 00:37:24 EDT Article-I.D.: duvan.812 Posted: Sat May 10 00:37:24 1986 Date-Received: Tue, 13-May-86 01:32:58 EDT References: <1298@umcp-cs.UUCP> Reply-To: zap@duvan.UUCP (Svante Lindahl) Organization: The Royal Inst. of Techn., Stockholm Lines: 197 Keywords: tacky programs, algol 68 In article <1298@umcp-cs.UUCP> jim@umcp-cs.UUCP writes: >/* > * xmas.c - a program to print The Twelve Days of Christmas > * using the C fall thru case statement. > * If this wasn't my idea, I appologize to whomever I > * got the idea from, but I wrote the program 5 years > * ago and I don't remember now. [...] Sorry this isnt' C, but I can't resist posting this... though I realize this is probably not a very apropriate newsgroup. It isn't my work, but I've lost track of who wrote it. Anyway it is an amusing piece of Algol-68-code. Example of execution under the TOPS-10 OS included after the code. BEGIN PROC readint = INT: (INT i; read(i); i); INT one=1, two=2, three=3, four=4, five=5, six=6, seven=7, eight=8, nine=9, ten=10, eleven=11, twelve=12; INT a=one; PRIO ME=5, LOVE=7, MY=7, LORDS=7, LADIES=7, PIPERS=7, DRUMMERS=7, MAIDS=7, SWANS=7, GEESE=7, GOLD=7, COLLY=7, FRENCH=7, TURTLE=7, PARTRIDGE=6; BOOL sent to=TRUE; OP THE = (BOOL a)BOOL:a, TWELFTH = (INT a)BOOL: a=twelve, ELEVENTH = (INT a)BOOL: a=eleven, TENTH = (INT a)BOOL: a=ten, NINTH = (INT a)BOOL: a=nine, EIGHTH = (INT a)BOOL: a=eight, SEVENTH = (INT a)BOOL: a=seven, SIXTH = (INT a)BOOL: a=six, FIFTH = (INT a)BOOL: a=five, FOURTH = (INT a)BOOL: a=four, THIRD = (INT a)BOOL: a=three, SECOND = (INT a)BOOL: a=two, FIRST = (INT a)BOOL: a=one; OP ME = (BOOL a, INT b)VOID: (IF a THEN print(b) FI), LOVE = (BOOL a, b)BOOL: (IF a THEN b ELSE FALSE FI), MY = (BOOL a, b)BOOL: a LOVE b, AND = (INT a)INT: a; MODE DATE = STRUCT(INT day, month); DATE christmas := (25, 12); OP LORDS = (INT a, b)INT: a*b, LADIES = (INT a, b)INT: a*b, PIPERS = (INT a, b)INT: a*b, DRUMMERS = (INT a, b)INT: a*b, MAIDS = (INT a, b)INT: a*b, SWANS = (INT a, b)INT: a*b, GEESE = (INT a, b)INT: a*b, GOLD = (INT a, b)INT: a*b, COLLY = (INT a, b)INT: a*b, FRENCH = (INT a, b)INT: a*b, TURTLE = (INT a, b)INT: a*b; OP LEAPING = (INT a)INT: a, DANCING = (INT a)INT: a, PIPING = (INT a)INT: a, DRUMMING = (INT a)INT: a, MILKING = (INT a)INT: a, SWIMMING = (INT a)INT: a, LAYING = (INT a)INT: a, RINGS = (INT a)INT: a, BIRDS = (INT a)INT: a, HENS = (INT a)INT: a, DOVES = (INT a)INT: a; OP PARTRIDGE = (INT a, b)INT: a+b; INT in a pear tree = 0; print("Factorial of "); print(day OF christmas := readint); print(" is "); IF day OF christmas > 12 THEN print("too big for this program."); stop FI; # Now we are ready.. # THE FIRST day OF christmas MY TRUE LOVE sent to ME a PARTRIDGE in a pear tree; THE SECOND day OF christmas MY TRUE LOVE sent to ME two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE THIRD day OF christmas MY TRUE LOVE sent to ME three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE FOURTH day OF christmas MY TRUE LOVE sent to ME four COLLY BIRDS three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE FIFTH day OF christmas MY TRUE LOVE sent to ME five GOLD RINGS four COLLY BIRDS three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE SIXTH day OF christmas MY TRUE LOVE sent to ME six GEESE LAYING five GOLD RINGS four COLLY BIRDS three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE SEVENTH day OF christmas MY TRUE LOVE sent to ME seven SWANS SWIMMING six GEESE LAYING five GOLD RINGS four COLLY BIRDS three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE EIGHTH day OF christmas MY TRUE LOVE sent to ME eight MAIDS MILKING seven SWANS SWIMMING six GEESE LAYING five GOLD RINGS four COLLY BIRDS three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE NINTH day OF christmas MY TRUE LOVE sent to ME nine DRUMMERS DRUMMING eight MAIDS MILKING seven SWANS SWIMMING six GEESE LAYING five GOLD RINGS four COLLY BIRDS three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE TENTH day OF christmas MY TRUE LOVE sent to ME ten PIPERS PIPING nine DRUMMERS DRUMMING eight MAIDS MILKING seven SWANS SWIMMING six GEESE LAYING five GOLD RINGS four COLLY BIRDS three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE ELEVENTH day OF christmas MY TRUE LOVE sent to ME eleven LADIES DANCING ten PIPERS PIPING nine DRUMMERS DRUMMING eight MAIDS MILKING seven SWANS SWIMMING six GEESE LAYING five GOLD RINGS four COLLY BIRDS three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree; THE TWELFTH day OF christmas MY TRUE LOVE sent to ME twelve LORDS LEAPING eleven LADIES DANCING ten PIPERS PIPING nine DRUMMERS DRUMMING eight MAIDS MILKING seven SWANS SWIMMING six GEESE LAYING five GOLD RINGS four COLLY BIRDS three FRENCH HENS two TURTLE DOVES AND a PARTRIDGE in a pear tree END .execut xmas A68: XMAS ALGOL68C Release 1.271 Unused space 991 Code generated 8r2271 LINK: Loading [LNKXCT A68 execution] 7 Factorial of +7 is +5040 Svante Lindahl, NADA, KTH Numerical Analysis & Computer Science UUCP: {seismo,mcvax}!enea!ttds!zap Royal Institute of Technology, Sweden ARPA: enea!ttds!zap@seismo.CSS.GOV EAN: zap@cs.kth.sunet