~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to html/answers2/answer73.html

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HTML><HEAD><TITLE>Answer to Exercise 73</TITLE></HEAD>
2
 
<BODY BGCOLOR="#FFFFFF">
3
 
<TABLE><TR><TD Valign="top"><IMG SRC="../icons/exercise.gif" ALT="??"><TD bgcolor="#FAA89B"><B>ANSWER TO EXERCISE 73</B><TR><TD><TD>
4
 
<P>
5
 
 
6
 
Here goes: we could implement the buttons with five
7
 
separate objects, essentially duplicates of each other.  (And by using a
8
 
class definition, this wouldn't look too bad.)  But if there were
9
 
500 slides this would be less reasonable.
10
 
<PRE>
11
 
[ ASlide w n;
12
 
   if (location~=Machine_Room) return -1;
13
 
   w=NextWord(); if (w=='slide') w=NextWord();
14
 
   switch(w)
15
 
   {   'first', 'one': n=1;
16
 
       'second', 'two': n=2;
17
 
       'third', 'three': n=3;
18
 
       'fourth', 'four': n=4;
19
 
       'fifth', 'five': n=5;
20
 
       default: return -1;                !  Failure!
21
 
   }
22
 
   w=NextWord(); if (w~='slide') wn--;    !  (Leaving word counter at the
23
 
                                          !  first misunderstood word)
24
 
   parsed_number=n;
25
 
   return 1;                              !  Success!
26
 
];
27
 
Global slide_settings --&#62; 5;              !  A five-word array
28
 
[ SetSlideSub;
29
 
   slide_settings--&#62;(noun-1) = second;
30
 
   print_ret "You set slide ", (number) noun,
31
 
             " to the value ", second, ".";
32
 
];
33
 
[ XSlideSub;
34
 
   print_ret "Slide ", (number) noun, " currently stands at ",
35
 
       slide_settings--&#62;(noun-1), ".";
36
 
];
37
 
Extend "set" first
38
 
           * ASlide "to" number                  -&#62; SetSlide;
39
 
Extend "push" first
40
 
           * ASlide "to" number                  -&#62; SetSlide;
41
 
Extend "examine" first
42
 
           * ASlide                              -&#62; XSlide;
43
 
</PRE>
44
 
 
45
 
</TABLE>
46
 
<HR>Back to <A HREF="../section27.html#ex73">the exercise in section 27</A><HR>
47
 
<SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright &#169; Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>