ANSWER TO EXERCISE 73 | |
Here goes: we could implement the buttons with five separate objects, essentially duplicates of each other. (And by using a class definition, this wouldn't look too bad.) But if there were 500 slides this would be less reasonable. [ ASlide w n; if (location~=Machine_Room) return -1; w=NextWord(); if (w=='slide') w=NextWord(); switch(w) { 'first', 'one': n=1; 'second', 'two': n=2; 'third', 'three': n=3; 'fourth', 'four': n=4; 'fifth', 'five': n=5; default: return -1; ! Failure! } w=NextWord(); if (w~='slide') wn--; ! (Leaving word counter at the ! first misunderstood word) parsed_number=n; return 1; ! Success! ]; Global slide_settings --> 5; ! A five-word array [ SetSlideSub; slide_settings-->(noun-1) = second; print_ret "You set slide ", (number) noun, " to the value ", second, "."; ]; [ XSlideSub; print_ret "Slide ", (number) noun, " currently stands at ", slide_settings-->(noun-1), "."; ]; Extend "set" first * ASlide "to" number -> SetSlide; Extend "push" first * ASlide "to" number -> SetSlide; Extend "examine" first * ASlide -> XSlide; |