Answer to Exercise 67

| ANSWER TO EXERCISE 67
    Object -> genies_lamp "brass lamp"
      with name "brass" "lamp",
           before
           [; Rub: if (self hasnt general) give self general;
                   else give self ~general;
                  "A genie appears from the lamp, declaring:^^
                   ~Mischief is my sole delight:^
                   If white means black, black means white!~^^
                   She vanishes away with a vulgar wink.";
           ];
    Object -> white_stone "white stone" with name "white" "stone";
    Object -> black_stone "black stone" with name "black" "stone";
    ...
    [ BeforeParsing;
       if (genies_lamp hasnt general) return;
       for (wn=1::)
       {   switch(NextWordStopped())
           {   'white': parse->(wn*2-3) = 'black';
               'black': parse->(wn*2-3) = 'white';
               -1: return;
           }
       }
    ];

Back to the exercise in section 26

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