Answer to Exercise 27

| ANSWER TO EXERCISE 27
    Object replicator "replicator"
      with name "replicator",
           grammar [;  return 'rc,'; ],
           orders
           [;  Give:
                   if (noun in self)
                       "The replicator serves up a cup of ",
                       (name) noun, " which you drink eagerly.";
                   "~That is not something I can replicate.~";
               default: "The replicator is unable to oblige.";
           ],
           life
           [;  Ask, Answer, Tell: "The replicator has no conversation skill.";
           ],
      has  talkable;
    Object -> "Earl Grey tea"    with name "earl" "grey" "tea";
    Object -> "Aldebaran brandy" with name "aldebaran" "brandy";
    Object -> "distilled water"  with name "distilled" "water";
    ...
    Verb "rc,"    * held      -> Give;
The point to note here is that the
`held`
token means 'held by the replicator' here, as the `actor` is the replicator, so this is a neat way of getting a 'one of the following phrases' token into the grammar.

Back to the exercise in section 16

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