To err is human
COULD A MACHINE ERR IS HUMANWho dares wins
I THINK YOU KNOW THE ANSWERNo one is more optimistic than myself
AREN'T YOU BEING A LITTLE NEGATIVEWhatever my problems are not one of them gets me down
CAN YOU ALWAYS EXPECT WHATEVER YOUR PROBLEMS TO BE ONE OF THEM GETS YOU DOWN
vars thisbit, thatbit; [my name is eliza] matches [my name ==] => [my name is eliza] matches [my name is ??thisbit] => thisbit => [my name is eliza] matches [??thisbit is ??thatbit] => thisbit => thatbit => [are you sure about ^^thisbit being ^^thatbit ?] => thisbit matches [my ??thisbit] => thisbit =>
Hint: To understand what happens in the final match above, it is important to look at what POP-11 does one step at a time, and to be very clear about how variables work. First, the value of the variable thisbit is obtained from memory, and the matches operation is applied to this list and the pattern [my ??thisbit]. As it happens, the pattern contains the same variable, thisbit, in a wild card position, so if the match succeeds, a new value will be given to the variable. This will simply replace the old value. Although the command looks peculiar because the same variable name appears twice, there is no contradiction provided you understand the sequence of operations that it gives rise to. If you find this difficult to follow, or you can't see that the final command will print out simply the list [name], it may help to go over the section on variables in chapter 1.
define greet(name); if [Mike Dave Chris Steve David] matches [== ^^name ==] then [Hello ^^name, are you one of the authors of this book?] => elseif name = [Aaron] then [Hello Aaron, I guess you wrote the preface] => else [Hello ^^name, pleased to meet you] => endif; enddefine; greet([David]); greet([Brian]); greet([Aaron]);
Notice how this procedure introduces a new way to use the pattern matcher: in the examples in the chapter we always had a fixed pattern written into the program, but there is nothing to stop us building up a pattern out of the data passed in to a procedure.
Modify the procedure so that it will work with an input giving both first name and surname, as in
greet([Mike Sharples]);
thing_of_colour
which gives examples of things of particular colours. The procedure should
take as its argument (i.e., input) a list which may contain
the name of a colour, and should return as its result the name of
something of that colour. It should not always return the same object
for a given colour, and it should return a suitable message if it
does not recognize a particular colour. Here is an example of an
interaction in which the procedure is called.
thing_of_colour([green]) => ** grass thing_of_colour([green]) => ** creme_de_menthe thing_of_colour([red]) => ** strawberries thing_of_colour([magenta]) => ** [Sorry I do not know the colour magenta] thing_of_colour([horse]) => ** [Sorry I do not know the colour horse] thing_of_colour([black]) => ** coal
Make a procedure which repeatedly asks the user to type in the name of a colour, and prints out an example of something of that colour, stopping only when the user types in the word bye.
I have a problem
STOP MOANING ABOUT YOUR PETTY AILMENTS
My mother cannot seem to understand me
I AM NOT SURPRISED, I CANNOT SEEM TO UNDERSTAND YOU EITHER
Are you intelligent?
A MIRACLE OF MODERN TECHNOLOGY AND ALL I GET IS QUESTIONS LIKE: ARE YOU INTELLIGENT?