??ANSWER TO EXERCISE 54

Class  Coin
  with name "coin" "coins//p",
       description "A round unstamped disc, presumably local currency.",
       list_together "coins",
       plural
       [;  print (string) (self.&name)-->0;
           if (~~(listing_together ofclass Coin)) print " coins";
       ],
       short_name
       [;  if (listing_together ofclass Coin)
           {   print (string) (self.&name)-->0; rtrue; }
       ],
       article
       [;  if (listing_together ofclass Coin) print "one"; else print "a";
       ];
Class  Gold_coin   class Coin with name "gold";
Class  Silver_coin class Coin with name "silver";
Class  Bronze_coin class Coin with name "bronze";
SilverCoin -> "silver coin";
... and so on

Back to the exercise in section 23
Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.