1.1 Is it true that this is an atom?
1.2 Is it true that this is an atom?
TURKEY
1.3 Is it true that this is an atom?
1492
1.4 Is it true that this is an atom?
3TURKEYS
1.5 Is it true that this is an atom?
L
1.6 Is it true that this is a list?
(ATOM)
1.7 Is it true that this is a list?
( ATOM TURKEY OR)
1.8 Is it true that this is a list?
(ATOM TURKEY) OR
1.9 Is it true that this is a list?
( (ATOM TURKEY) OR)
1.10 Is it true that this is an S-expression?
XYZ
1.11 Is it true that this is an S-expression?
(X Y Z)
1.12 Is it true that this is an S-expression?
( (X Y) Z)
1.13 Is it true that this is a list?
(HOW ARE YOU DOING SO FAR)
1.14 How many S-expressions are in the list
(HOW ARE YOU DOING SO FAR)
and what are they?
1.15 Is it true that this is a list?
( ( (HOW) ARE) ( (YOU) (DOING SO) )
FAR)
1.16 How many S-expressions are in the list?
( ( (HOW) ARE) ( (YOU) (DOING SO)
) FAR) and what are they?
1.17 Is it true that this is a list?
( )
1.18 Is it true that this is a list?
( (
) (
) ( ) ( ) )
1.19 What is the CAR of L, Where L is the argument
(A B
C)
1.20 What is the CAR of L, Where L is the argument
( (A B C)
X Y Z)
1.21 What is the CAR of L, Where L is the argument
HOTDOG
1.22 What is the CAR of L, Where L is the argument
(
)
PRINCIPLE No. 1: CAR is only defined for non-null lists.
1.23 What is the CAR of L, where L is the argument
( (
(HOTDOGS) ) (AND) (PICKLE) RELISH)
1.24 What is (CAR L), where L is the argument
( (
(HOTDOGS) ) (AND)
(PICKLE) RELISH)
1.25 What is the (CAR (CAR L) ), Where L is the argument
(
(HOTDOGS) ) (AND))
1.26 What is the CDR of L, where L is the argument
(A B
C)
Note: “CDR” is pronounced
“couder”.
1.27 What is the CDR of L, where L is the argument
( (A B C)
X Y Z)
1.28 What is (CDR L), where L is the argument
(
(X) T R)
1.29 What is (CDR A), where A is the argument
HOTDOGS
1.30 What is (CDR L), where L is the argument
(
)
Principle No. 2: CDR is only defined for non-null lists; the CDR of any list is always another list.
1.31 What is (CAR (CDR L) ), where L is the argument
( (B) (X
Y) ( (C)
) )
1.32 What is (CDR (CDR L) ), where L is the argument
( (B) (X
Y) ( (C)) )
1.33 What is (CDR (CAR L) ), where L is the argument
( A (B
(C) ) D)
1.34 What does (CAR L) take as an argument?
1.35 What does (CDR L) take as an argument?
1.36 What is the CONS of the atom A and the list L,
where A is the argument PEANUT, and L is the argument
(BUTTER
AND JELLY)
This can alternatively
be asked (CONS A L). Read: “CONS the atom A onto the list L.”
1.37 What is the CONS of S and L, where S is (MAYONNAISE AND), and L is (PEANUT BUTTER AND JELLY)
1.38 What is (CONS S L), where S is ( (HELP) THIS), and L is (IS VERY ( (HARD) TO LEARN) )
1.39 What does CONS take as its arguments?
1.40 What is (CONS S L), where S is (A B (C) ), and L is ( )
1.41 What is (CONS S L), where S is A, and L is ( )
1.42 What is (CONS S L), where S is (A B (C) ), and L is B
1.43 What is (CONS S L), where S is A, and L is B
Principle No. 3: The second argument of (CONS S L) must be a list, and the result must also be a list.
1.44 What is (CONS S (CAR L) ), where S is A, and L is ( (B) C C)
1.45 What is (CONS S (CDR L) ), where S is A, and L is ( (B) C D)
1.46 Is it true that the list, L is the null list, where L is ( )?
The question is alternatively
read as: (NULL L).
1.47 Is (NULL L) true or false, where L is the argument (A B C)
1.48 Is (NULL L) true or false, where L is the argument A
1.49 Is it true, or false, that S is an atom, where S is the argument HARRY
1.50 Is (ATOM S) true, or false, where S is HARRY
1.51 Is (ATOM S) true, or false, where S is (HARRY HAD A HEAP OF APPLES)
1.52 How many arguments does ATOM take? What are they?
1.53 Is 1.54 Is (ATOM (CDR L) ) true or false, where L is
(HARRY HAD A HEAP OF APPLES)
1.55 Is (ATOM (CAR (CDR L) ) ) true or false, where L
is (SWING LOW SWEET CHERRY)
1.56 Is (ATOM (CAR (CDR L) ) ) true or false, where L
is (SWING (LOW SWEET) CHERRY)
1.57 True or False: A1 and A2 are the same atom, where
A1 is HARRY,and A2 is HARRY
1.58 Is (EQ A1 A2) true or false, where A1 is the
argument HARRY, and A2 is the argument HARRY.
1.59 Is (EQ A1 A2) true or false, where A1 is the
argument is MARGARINE,and A2 is BUTTER
1.60 How many arguments does EQ take, and what are
they?
1.61 Is (EQ A L) true, or false where A is STRAWBERRY,
and L is (STRAWBERRY)
Principle No. 5: (EQ A1 A2) takes two
arguments.
Both of the arguments must be atoms, which begin with letters.
1.62 Is (EQ (CAR L) A) true or false where L is (MARY
HAD A LITTLE CHOP),and A is MARY.
1.63 Is (EQ (CDR L) A) true or false where L is (SOURED
MILK), and A is MILK
1.64 Is (EQ (CAR L) (CAR (CDR L) ) ) true or false
where L is (BEANS BEANS ARE GOOD FOR YOUR HEART)
Chapter 2 2.1 True or False: (ISLAT L) where L is (JACK SPRAT
COULD EAT NO CHICKEN FAT)
2.2 True or False: (ISLAT L) where L is ( (JACK) SPRAT
COULD EAT NO CHICKEN FAT)
2.3 True or False: (ISLAT L) where L is (JACK (SPRAT
COULD) EAT NO CHICKEN FAT)
2.4 True or False: (ISLAT L) where L is ( )
2.5 True or False: a LAT is a list of atoms
2.6 Write the function (ISLAT L), using some but not
necessarily all of the following functions: CAR, CDR, CONS,
NULL, 2.7 This is the function (ISLAT L) defined with the
help of the functions,NULL, CAR, CDR and ATOM
2.8 How do you arrive at the answer T for the function
(ISLAT L)?
2.9 What is the first question asked by (ISLAT L)?
2.10 What is meaning of the line ( (NULL L) T), where
L is (BACON AND EGGS)?
2.11 What is next question?
2.12 What is the meaning of the line ( (ATOM (CAR L)
(ISLAT (CDR L)
) ), where L is (BACON AND EGGS)?
2.13 What is the meaning of (ISLAT (CDR L) )?
2.14 Now what is the argument L for ISLAT?
2.15 What is the next question?
2.16 What is the meaning of the line ( ( NULL L) T)
where L is now (AND EGGS)
2.17 What is the next question that must be asked?
2.18 What is the meaning of the line ( (ATOM (CAR L) )
(ISLAT (CDR L)) ) where L is (AND EGGS)?
2.19 What is the meaning of (ISLAT (CDR L) )
2.20 what is the next question?
2.21 What is the meaning of the line ( (NULL L) T)
where L is now (EGGS)
2.22 What is the next question that must be asked?
2.23 What is the meaning of the line ( (ATOM (CAR L) )
(ISLAT (CDR L) ) ) where L is now (EGGS)
2.24 What is the meaning of (ISLAT (CDR L) ) ?
2.25 What is the argument for ISLAT?
2.26 What is the meaning of the line ( (NULL L) T)
where L is now ( )
2.27 Do you remember the problem about (ISLAT L)
2.28 Can you describe what the function ISLAT does in
your own words?
2.29 This is the function (ISLAT L) again:
(DEFUN ISLAT(L)
2.30 What is the first question to be asked?
2.31 What is the meaning of the line ( (NULL L) T) where L is (BACON
(AND EGGS) )
2.32 What is the next question?
2.33 What is the meaning of the line ( (ATOM (CAR L) ) (ISLAT (CDR L)
) ) where L is (BACON (AND EGGS) )
2.34 What is the meaning of (ISLAT (CDR L) )?
2.35 What is the meaning of the line ( (NULL L) T) where L is ( (AND
EGGS) )
2.36 What is the next question?
2.37 What is the meaning of the line ( (ATOM (CAR L) ) (ISLAT (CDR L)
) ) where L is ( (AND EGGS))
2.38 What is the next question?
2.39 What is the meaning of the question T?
2.40 Is T true?
2.41 T
2.42 Why is T the last question?
2.43 What is the meaning of the line (T F)
2.44 What is the meaning of the line
2.45 Can you describe how we arrived at the value F for (ISLAT L) where
L is (BACON (AND EGGS) )?
2.46 Is it true or false that A is a member of LAT, where A is the argument
TEA and LAT is the argument (COFFEE TEA
OR 2.47 Is (MEMBER A LAT) true or false where A is POACHED and LAT is (FRIED
EGGS AND SCRAMBLED EGGS)
2.48 This is the function (MEMBER A LAT):
2.49 How do you arrive at the value T for the above function?
2.50 What is the first question asked by (MEMBER A LAT)
Commandment No. 1: Thou shall always ask NULL as the first
question in describing any function
2.51 What is the meaning of the line ( (NULL LAT) F) where LAT is (MASHED
POTATOES AND MEAT GRAVY)
2.52 What is the next question?
2.53 What is the meaning of the line ( (EQ (CAR LAT) A) T) where
A is MEAT and LAT is (MASHED POTATOES
AND 2.54 What is the next question?
2.55 Is T really a question?
2.56 Give an example of a question to which the answer is contained
in the question
2.57 What is the meaning of the line (T (MEMBER A (CDR LAT) ) )
2.58 What are the arguments for MEMBER now?
2.59 What is the next question?
2.60 Is (NULL LAT) true or false where LAT is (POTATOES AND MEAT GRAVY)
2.61 What do we do now?
2.62 What is the next question?
2.63 What is (EQ (CAR LAT) A) where A is MEAT and LAT is (POTATOES AND
MEAT GRAVY)
2.64 What do we do now?
2.65 What is the next question?
2.66 What is T?
2.67 What is the meaning of the line (T (MEMBER A (CDR LAT) ) )?
2.68 What are the arguments of MEMBER now?
2.69 What is the next question?
2.70 What do we do now?
2.71 What is the next question?
2.72 What do we do now?
2.73 What is the next question?
2.74 What is the value of the line (T (MEMBER A (CDR LAT) ) )?
2.75 What do we do now?
2.76 What are the new arguments?
2.77 What is the next question?
2.78 What do we do now?
2.79 What is the next question?
2.80 What is the value of the line ( (EQ (CAR LAT) A) T)
2.81 What is the value of the function (MEMBER A LAT) where A is MEAT
and LAT is (MEAT GRAVY)
2.82 What is the value of the function (MEMBER A LAT) where A is MEAT
and LAT is (AND MEAT GRAVY)
2.83 What is the value of the function (MEMBER A LAT) where A is MEAT
and LAT is (POTATOES AND MEAT 2.84 What is the value of the function (MEMBER A LAT) where A is MEAT
and LAT is (MASHED POTATOES AND 2.85 Just to make sure you have it right, let’s run through it again
quickly, what is the value of
(DEFUN MEMBER (A LAT)
Where A is MEAT and Lat is (MASHED POTATOES AND MEAT GRAVY)
2.86 (NULL LAT)
2.87 (EQ (CAR LAT) A)
2.88 T
2.89 (NULL LAT)
2.90 (EQ (CAR LAT) A)
2.91 T
2.92 (NULL LAT)
2.93 (EQ (CAR LAT) A)
2.94 T
2.95 (NULL LAT)
2.96 (EQ (CAR LAT) A)
2.97 What is the value of (MEMBER A LAT) where A is MEAT and LAT is
(MEAT GRAVY)
2.98 What is the value of (MEMBER A LAT) where A is MEAT and LAT is
(AND MEAT GRAVY)
2.99 What is the value of (MEMBER A LAT) where A is MEAT and LAT is
(POTATOES AND MEAT GRAVY)
2.100 What is the value of (MEMBER A LAT) where A is MEAT and LAT is
(MASHED POTATOES AND MEAT 2.101 What is the value of (MEMBER A LAT) where A is LIVER and LAT is
(BAGELS AND LOX)
2.102 (NULL LAT)
2.103 (EQ (CAR LAT) A)
2.104 T
2.105 (NULL LAT)
2.106 (EQ (CAR LAT) A)
2.107 T
2.108 (NULL LAT)
2.109 (EQ (CAR LAT) A)
2.110 T
2.111 (NULL LAT)
2.112 What is the value of (MEMBER A LAT) where A is LIVER and LAT is
( )
2.113 What is the value of (MEMBER A LAT) where A is LIVER and LAT is
(LOX)
2.114 What is the value of (MEMBER A LAT) where A is LIVER and LAT is
(AND LOX)
2.115 What is the value of (MEMBER A LAT) where A is LIVER and LAT is
(BAGELS AND LOX)
Chapter 3 3.1 What is (REMBER A LAT) where A is MINT and LAT is (LAMB CHOPS AND
MINT JELLY)
3.2 (REMBER A LAT) where A is MINT and LAT is (LAMB CHOPS AND MINT
FLAVOURED MINT JELLY)
3.3 (REMBER A LAT) where A is TOAST and LAT is (BACON LETTUCE AND TOMATO)
3.4 (REMBER A LAT) where A is CUP and LAT is (COFFEE CUP TEA CUP
AND HICK CUP)
3.5 What does (REMBER A LAT) do?
3.6 What steps will we use to do this?
3.7 How do we ask if A is the same as (CAR LAT)?
3.8 What would be the value of (REMBER A LAT) if A is the same as (CAR
LAT) ?
3.9 What do we do if A is not the same as (CAR LAT)?
3.10 How do we find out if A is somewhere in the rest of LAT?
3.11 Let us now use the ideas developed so far to write the function
REMBER:
(DEFUN
REMBER (A LAT)
3.12 Now we think that this is the function REMBER:
(DEFUN REMBER (A LAT)
3.13 Now lets see if this function works. What is the first question?
3.14 What do we do now?
3.15 (EQ (CAR LAT) A)
3.16 Is this the correct value of the function?
3.17 But did we really use a good example?
3.18 What does a (REMBER A LAT) do?
3.19 What steps do we use to do this?
3.20 What is the value of (REMBER A LAT) where A is AND and LAT is (BACON
LETTUCE AND TOMATO)
3.21 Let us see if this function works. What is the first question asked
by REMBER?
3.22 What do we do now?
3.23 (EQ (CAR LAT) A)
3.24 What is the meaning of the line ( T
REMBER A (CDR LAT) ) )
3.25 (NULL LAT)
3.26 (EQ (CAR LAT) A)
3.27 What is the meaning of the line ( T
REMBER A (CDR LAT) ) )
3.28 (NULL LAT)
3.29 (EQ (CAR LAT) A)
3.30 What is the value of the function (REMBER A LAT)
3.31 Is this correct?
3.32 What did we do wrong?
3.33 How can we keep from losing the atoms BACONS and LETTUCE?
Commandment No. 2: Thou shall use CONS to
build lists.
3.34 Let’s just see what happens when we use CONS:
(DEFUN REMBER (A LAT)
3.35 What is the first question?
3.36 What do we do now?
3.37 (EQ (CAR LAT) A)
3.38 What is the meaning of the line (T (CONS (CAR LAT) (REMBER
A (CDR LAT) ) ) )
3.39 What is the meaning of (REMBER A (CDR LAT) )
3.40 (NULL LAT)
3.41 (EQ (CAR LAT) A)
3.42 What is the meaning of the line (T (CONS (CAR LAT) (REMBER
A (CDR LAT) ) ) )
3.43 What is the meaning of (REMBER A (CDR LAT) )
3.44 (NULL LAT)
3.45 (EQ (CAR LAT) A)
3.46 What is the value of the line ( (EQ (CAR LAT) A) (CDR LAT) )
3.47 Are we finished?
3.48 We now have a value for (REMBER A (CDR LAT) ),
3.49 What is the result when we CONS LETTUCE onto (TOMATO)
3.50 What does (LETTUCE TOMATO) represent?
3.51 Are we finished yet?
3.52 We now have a value for (REMBER A (CDR LAT) ), where A was AND
and (CDR LAT) was (LETTUCE AND 3.53 What is the result when we CONS BACON onto (LETTUCE TOMATO)
3.54 What does (BACON LETTUCE TOMATO) represent?
3.55 Are we finished yet?
3.56 Can you put in your words how we arrived at the final value (BACON
LETTUCE TOMATO)
3.57 What is the value of the function
(DEFUN REMBER (A LAT)
3.58 (NULL LAT)
3.59 (EQ (CAR LAT) A)
3.60 T
3.61 What is the meaning of (CONS (CAR LAT) (REMBER A (CDR LAT) ) )
)
3.62 (NULL LAT)
3.63 (EQ (CAR LAT) A)
3.64 T
3.65 What is the meaning of (CONS (CAR LAT) (REMBER A (CDR LAT) ) )
)
3.66 (NULL LAT)
3.67 (EQ (CAR LAT) A)
3.68 What is the value of the line
3.69 Now what?
3.70 Now what?
3.71 Now that we have completed REMBER, try this example:
3.72 What is (FIRSTS L) where L is ( (APPLE PEACH PUMPKIN) (PLUM PEAR
CHERRY) (GRAPE RAISIN PEA) 3.73 What is (FIRSTS L) where L is ( (A B) (C D) (E F) )
3.74 What is (FIRSTS L) where L is ( )
3.75 What is (FIRSTS L) where L is ( (FIVE PLUMS) (FOUR) (ELEVEN GREEN
ORANGES) )
3.76 In your own words what does (FIRSTS L) do?
3.77 See if you can write the functions FIRSTS
3.78 Why (DEFUN FIRSTS ( L ) ?
3.79 Why ( COND ?
3.80 Why ( ( NULL L) ) ?
3.81 Why (T ?
3.82 Why ( CONS ?
3.83 Why (FIRSTS (CDR L) ) ?
3.84 Why ) ) ) ?
3.85 Keeping in mind the definition of ( FIRSTS L), what is a typical
element of the value of (FIRSTS L), where L is ( ( A B )
( 3.86 What is another typical element?
3.87 Suppose there was a function (SECONDS L) what would
be a typical element of the value of (SECONDS L)
where L 3.88 How do we describe a typical element for (FIRSTS L)
3.89 As we find a typical element for (FIRSTS L) what do we do
with it?
Commandment No. 3: Thou shall always
realize when
building a list, thou need only describe the first typical element, and
then CONS it onto the natural recursion.
3.90 From Commandment No. 3, we can now fill in more of the function
( FIRSTS L). what does the last line look like now?
3.91 What does the function do?
(DEFUN FIRSTS
( L )
Where L is ( (A B) (C D) (E F) )
3.92 (NULL L) where L is ( (A B) (C D) (E F) )
3.93 What is the meaning of the line ( T (CONS (CAR L) ) (FIRSTS (CDR
L) ) ) )
3.94 (NULL L) where L is ( (C D) (E F) )
3.95 What is the meaning of the line ( T (CONS (CAR L) ) (FIRSTS (CDR
L) ) ) )
3.96 (NULL L) where L is ( (E F) )
3.97 What is the meaning of the line ( T (CONS (CAR L) ) (FIRSTS (CDR
L) ) ) )
3.98 (NULL L)
3.99 Now what is the value of the line ( (NULL L) )
3.100 What do we need to CONS atoms onto?
3.101 What value can we give the function in the case that (NULL L)
is true for the purpose of CONS ing?
3.102 With ( ) as a value, we now have three CONS steps to go
back and pick up.
I. We need to: 1. CONS E onto (
)
II. We need to: 1. CONS A onto the value of 2
III. We need to CONS A onto the CONS of C onto the CONS
of E onto ( )
In any case what is the final value of (FIRSTS L) ?
3.103 With which of the three alternatives are you most comfortable?
3.104 (INSERTR OLD NEW LAT) where OLD is FUDGE, NEW is TOPPING and LAT
is (ICE CREAM WITH FUDGE 3.105 (INSERTR OLD NEW LAT) where OLD is AND, NEW is JALAPENO and LAT
is (TACOS TAMALES AND 3.106 (INSERTR OLD NEW LAT) where OLD is D, NEW is E and LAT is (A B
C D F G D H)
3.107 In your own words what does (INSERTR OLD NEW LAT) do?
3.108 See if you can write the function (INSERTR OLD NEW LAT)
3.109 What is the value of the INSERTR we just wrote, where OLD is FUDGE,
NEW is TOPPING and LAT is
(ICE 3.110 Notice that so far this is the same as REMBER, but for (INSERTR
OLD NEW LAT)
What do we do, where (EQ (CAR LAT) OLD) is
true?
3.111 How is this done?
3.112 Now we have
(DEFUN INSERTR (OLD
NEW LAT)
3.113 Is this the list we wanted?
3.114 What still needs to be done?
3.115 How can we include OLD before NEW?
3.116 Now you should be able to write the rest of the function
(INSERTR OLD NEW LAT)
3.117 Now try (INSERTL OLD NEW LAT)
3.118 Did you think of a different way to do that?
3.119 Now try to write (SUBST OLD NEW LAT)
HINT: (SUBST OLD NEW LAT)
replaces the first occurrence of OLD in the LAT with the atom NEW. For
Example ANSWERS
Chapter 1 1.1 Yes
1.2 Yes
1.3 No
1.4 No
1.5 Yes
1.6 Yes
1.7 Yes
1.8 No
1.9 Yes
1.10 Yes
1.11 Yes
1.12 Yes
1.13 Yes
1.14 ( 6 ) HOW, ARE, YOU, DOING, SO and FAR.
1.15 Yes
1.16 ( 3 )
1.17 Yes
1.18 Yes
1.19 A
1.20 (A B C)
1.21 No answer
1.22 No answer
1.23 ( (HOTDOGS) ) ----Read as: " The list of the list
composed of the
atom HOTDOGS."
1.24 ( ( (HOTDOGS) ) )
1.25 (HOTDOGS)
1.26 (B C)
1.27 (X Y Z)
1.28 (T R)
1.29 No answer
1.31 (X Y)
1.32 ( ( ( C ) ) )
1.33 No answer
1.34 (CAR L) takes any non-null list as its argument L.
1.35 (CDR L) takes any non-null list as its argument L.
1.36 (PEANUT BUTTER AND JELLY)
1.37 ( (MAYONNAISE AND) PEANUT BUTTER AND JELLY)
1.38 ( ( (HELP) THIS) IS VERY ( (HARD) TO LEARN) ).
1.39 ( CONS S L) takes two arguments: the first one S, is
any S-expression.
The second one L, is any list.
1.40 ( (A B (C) ) )
1.41 ( A )
1.42 No answer
1.43 No answer
1.44 (A B)
1.45 (A C D)
1.46 Yes
1.47 False
1.48 No answer
1.49 True
1.50 True
1.51 False
1.52 ATOM takes one argument, which is any S-expression.
1.53 True
1.55 True
1.56 False
1.57 True
1.58 True
1.59 False
1.60 EQ takes two arguments , both of which must be atoms.
1.61 No answer
1.62 True
1.63 No answer
1.64 True
Chapter 2 2.1 True
2.2 False
2.3 False
2.4 True
2.5 True
2.6 We did not expect you to know this, but we wanted you to realize
that you are still missing some necessary
relationships. 2.7 True
2.8 We don’t expect you to know this one either. The answer is arrived
at through asking the questions of (ISLAT L).
2.9 (NULL L)
2.10 (NULL L) asks if the argument L is the null list. If it is, then
the value of the function is T. If it is not then we ask the
next 2.11 (ATOM (CAR L) )
2.12 (ATOM (CAR L) ) asks if the first S-expression of the list L is
an atom. If (CAR L) is an atom, then we want to know
if 2.13 (ISLAT (CDR L) ) finds out if the rest of the list L is composed
only of atoms by referring us back to the original
function, 2.14 Now the argument L is (CDR L) which is (AND EGGS).
2.15 (NULL L)
2.16 (NULL L) asks if the argument L is the null list. If it is, then
the value of the function is T. If it is not then we ask the
next 2.17 (ATOM (CAR L) )
2.18 (ATOM (CAR L) ) asks if (CAR L) is an atom. If it is an atom, then
the value of the function is (ISLAT (CDR L) ). If it
is 2.19 (ISLAT (CDR L) finds out if the rest of the L is composed only
of atoms by referring us back again to the original
function 2.20 (NULL L)
2.21 (NULL L) asks if the argument L is the null list. If it is, then
the value of the function is T--True. If it is not then we ask
the 2.22 (ATOM (CAR L) )
2.23 (ATOM (CAR L) ) asks if (CAR L) is an atom. If it is then the value
of the function is (ISLAT (CDR L) ). If (CAR L)
is 2.24 (ISLAT (CDR L) finds out if the rest of the L is composed only
of atoms by referring us back again to the original
function 2.26 (NULL L) asks if the argument L is the null list. If it is, then
the value of the function is T. If it is not then we ask the
next 2.27 Probably not.
2.28 Here are our words:
2.29 False
2.30 (NULL L)
2.31 (NULL L) asks if the argument L is the null list. If it is, then
the value of the function is T. If it is not then we ask the
next 2.32 (ATOM (CAR L) )
2.33 (ATOM (CAR L) ) asks if (CAR L) is an atom. If it is then the value
of the function is (ISLAT (CDR L) ). If (CAR L)
is 2.34 (ISLAT (CDR L) ) checks to see if the rest of the list L is composed
only of atoms, by referring us back to (ISLAT
L) 2.35 (NULL L) asks if the argument L is the null list. If it is, then
the value of the function is T. If it is not then we ask the
next 2.36 (ATOM (CAR L) )
2.37 (ATOM (CAR L) ) asks if (CAR L) is an atom. If it is then the value
of the function is (ISLAT (CDR L) ). If (CAR L)
is 2.38 T
2.39 T asks if T is true.
2.40 Yes
2.41 T
2.42 Because we do not need to ask any more questions.
2.43 T asks if T is true.
2.44 These are just the closing parentheses which match “(COND”, “(DEFUN”
and “(ISLAT” at the beginning of
the 2.45 Here is one way to say it:
2.46 True
2.47 False
2.48 True
2.49 The value is arrived at by asking the questions about (MEMBER A
LAT).
2.50 (NULL LAT)
2.51 (NULL LAT) asks if the LAT is the null list. If it is, then the
value of the function is F false, since the atom MEAT was
not 2.52 (EQ (CAR LAT) A)
2.53 (EQ (CAR LAT) A) asks if the CAR of the LAT is the same as the
atom A. if it is, then the value of the function is T. If
it 2.54 T
2.55 Yes
2.56 Here’s ours:
2.57 Now that we know that the LAT is not null, and we know that the
CAR of LAT is not the same atom as A, we want
to 2.58 A is MEAT and LAT is now (CDR LAT) --- (POTATOES AND MEAT GRAVY).
2.59 (NULL LAT)
2.60 F – false.
2.61 Ask the next question
2.62 (EQ (CAR LAT) A).
2.63 F—false
2.64 Ask the next question.
2.65 T
2.66 T --- true
ATOM and
EQ
(DEFUN ISLAT(L)
(COND
( (NULL L) T)
( (ATOM (CAR L) ) (ISLAT(CDR L) ) )
(T F)
)
)
What is the value of (ISLAT L),
where L is the argument (BACON AND EGGS)?
(COND
( (NULL L) T)
( (ATOM (CAR L) ) (ISLAT (CDR L) ) )
(T F)
)
)
What is the value of (ISLAT L),where L is now (BACON (AND EGGS)
)?
) ) )
MILK)
(DEFUN MEMBER (A LAT)
(COND
( (NULL LAT) F)
( (EQ (CAR LAT) A) T)
(T (MEMBER A (CDR LAT) ) )
)
)
What is the value of (MEMBER A LAT) where A is MEAT and LAT is (MASHED
POTATOES AND MEAT GRAVY)
MEAT GRAVY)
GRAVY)
MEAT GRAVY)
(COND
( (NULL LAT) F)
( (EQ (CAR LAT) A) T)
(T (MEMBER A (CDR LAT) ) )
)
)
GRAVY)
(COND
( (EQ (CAR LAT) A) (CDR LAT) )
(T (REMBER A (CDR LAT) ) )
) )
)
What is missing from here?
(COND
( (NULL LAT) ( ) )
( (EQ (CAR LAT) A) (CDR LAT) )
(T (REMBER A (CDR LAT) ) )
) )
)
What is the value of (REMBER A LAT) where A is BACON and LAT is (BACON
LETTUCE AND TOMATO)
(COND
( (NULL LAT) ( ) )
( (EQ (CAR LAT) A) (CDR LAT) )
(T (CONS (CAR LAT) (REMBER A (CDR LAT) ) ) )
)
)
Now, what is the value of (REMBER A LAT) where A is AND and LAT is
(BACON LETTUCE AND TOMATO)
where A is AND and
LAT is (BACON LETTUCE AND
TOMATO)
where A is AND and (CDR
LAT) is (AND TOMATO) This value is (TOMATO). This is not the final
value, so what
must we do?
TOMATO) This value was (LETTUCE TOMATO).
This is not the final value,
so what must we do?
(COND
( (NULL LAT) ( ) )
( (EQ (CAR LAT) A) (CDR LAT) )
(T (CONS (CAR LAT) (REMBER A (CDR LAT) ) ) )
) )
)
Where A is AND and LAT is (BACON LETTUCE AND TOMATO)
(REMBER A LAT) where A is
SAUCE and LAT is (SOY SAUCE AND TOMATO SAUCE)
(BEAN
CARROT EGGPLANT)
Remember the
Commandments!
C D ) ( E F) )
is ( (A
B) (C D) (E F) )
NOTE: You have just read an important statement in this page. Please read
it again.
(COND
( (NULL L) ( ) )
( T (CONS (CAR (CAR L) ) (FIRSTS (CDR L) ) ) )
2. CONS C onto the value of 1
3. CONS A onto the value of 2
or alternatively
2. CONS C onto the value of 3
3. CONS E onto ( )
or alternatively
FOR DESSERT)
SALSA)
CREAM WITH FUDGE FOR DESSERT)
(COND
( (NULL LAT) ( ) )
( (EQ (CAR LAT) OLD) (CONS NEW (CDR LAT) ) )
(T (CONS (CAR LAT) (INSERTR OLD NEW (CDR LAT) ) ) )
)
)
What is (INSERTR OLD NEW LAT) where OLD is FUDGE, NEW is TOPPING and
LAT is (ICE CREAM WITH FUDGE FOR DESSERT)
Do it.
Hint: INSERTL inserts the atom NEW to the left of the first occurrence
of the atom OLD
where OLD is
FUDGE, NEW is TOPPING and
LAT is (ICE CREAM WITH FUDGE FOR DESSERT), the value
is
(ICE CREAM WITH
TOPPING FOR DESSERT). Now you have the
idea.
Because ATOM is a string of characters
beginning with an A.
Because TURKEY is a string of
characters beginning with a letter
Because 1942 is a string of characters
beginning with a digit.
Note: Numbers are not atoms yet.
Because 3TURKEYS is a string of characters
beginning with a digit.
Because L is a string of ---one----
characters beginning with a letter.
Because (ATOM) is an atom enclosed by
parentheses.
Because it is a collection of atoms
enclosed by parentheses.
Since this is only two S-expressions
not enclosed by parentheses. The first one is a list containing two atoms
and the
second one is an atom.
Because the two S-expressions are now
enclosed by parentheses.
Because all atoms
are S-expressions.
Because it is a list.
Because all lists
are S-expressions.
Because it is a collection
of S-expressions enclosed by parentheses.
Because it is a collection
of S-expressions enclosed by parentheses.
( ( HOW ) ARE ), (
( YOU ) ( DOING SO ) ) and FAR
Because it is a collection
of zero S-expressions enclosed by parentheses. This special S- expression
is called the null-list.
Because it is a collection
of S-expressions enclosed by parentheses
Because A is the first atom
of this non-null list.
Because (A B C) is the first
S-expression of this non-null list.
Since you cannot ask for
the CAR of an atom.
Since you cannot ask for
the CAR of the null list.
Because ( (HOTDOGS) ) is
the first S-expression of this non-null list.
Because (B C) is the list
L, without (CAR L).
Since (CDR L) is just another
way to ask for "The CDR of the list L".
Since you cannot ask for
the CDR of an atom
1.30 No answer
Since you cannot ask for
the CDR of the non null list.
Because ( (X Y) ( (C) )
) is (CDR L) and (X Y) is the CAR of (CDR L).
Because ( (X Y) ( (C) )
) is (CDR L) and ( ( (C) ) ) is the CDR of (CDR L).
Since (CAR L) is an atom
and CDR will not take an atom for an argument;
see Principle No.2.
Because CONS sticks an atom
onto the front of a list.
Because CONS sticks any
S-expression onto the front of the list.
Since ( ) is a list.
Since the second argument
L must be a list
why? See Principle
No. 3
Because it is the
list composed of zero S-expressions.
Because it is a non-null
list
Because you cannot ask (
NULL L) of an atom.
Because HARRY is a string
of characters beginning with a letter.
Since (ATOM S) is just another
way to ask: "Is it true or false, that S is an atom?"
Since the argument S is
a list.
Because (CAR L) is HARRY
and HARRY is an atom.
Because (CDR L) is (LOW
SWEET CHERRY) and (CAR (CDR L) is (LOW SWEET)
which is a list.
Because (CDR L) is ( (LOW
SWEET) CHERRY) and (CAR (CDR L) is (LOW
SWEET) which is a list.
Because both A1 and A2 are
HARRY.
Because (EQ A1 A2) is just
another way to ask: "Are A1 and A2 the same atom?".
Since the arguments A1 and
A2 are different atoms.
Since neither argument of
EQ can be a list.
Because (CAR L) is the atom
MARY and the argument A is also the atom MARY.
See
Principles No. 2 and
5
This compares the first
and second atoms in the list.
Because each S-expression in L is an
atom.
Since (CAR L) is a list
Since one of the S-expression in L is
a list.
Because ( ) contains no
lists, and because it does not contain any lists, it must be a LAT
Note: Every LAT is a list, but
not every list is a LAT.
Go on to the next
question. Good luck.
The function (ISLAT L) where L is (BACON
AND EGGS) has the value T -- true— because L is a LAT.
HINT: Write down the function (ISLAT
L) and refer to it for the next group of questions.
Note: “(COND” is only a necessary
stem that you will have to learn to live with.
Similarly “(DEFUN” is the necessary
part of the scenery, but for your purposes, it is as useful as a screen
door on a
submarine sandwich.
question.
In this case, L is not the null list, so we ask the next question.
the rest
of L is also composed only of atoms. If (CAR L)
is not an atom, then we ask the next question. In this case,
(CAR
L) is
an atom, so the value of the function is (ISLAT (CDR L) ).
but now with
a new argument.
question.
In this case, L is not the null list,
so we ask the next question.
not an atom, then
we ask the next question. In this
case, (CAR L) is an atom. So we to find out if the rest of the list
L is
composed of only atoms.
(ISLAT L),
but this time with the argument (CDR L)
which is (EGGS)
next
question. In this case, L is not the null list,
so we ask the next question.
not an atom, then ask
the next question. In this case,
(CAR L) is an atom, so once again we look at (ISLAT (CDR L) ).
(ISLAT L),but with L
replaced by (CDR L)
2.25 ( )
question.
In this case, L is not the null list, so we ask
the next question. In this case, ( ) is the null list. Therefore,
the value
of the function (ISLAT
L).where L is (BACON AND EGGS)
is T or True.
The function (ISLAT L) has
a value of T if the list L is a list of atoms, where L is (BACON AND EGGS)
“ISLAT looks at each S-expression,
in turn, and asks if each S-expression is an atom, until it runs out of
S-expressions.
When it runs out
without encountering a list, the
function’s value is T. As soon as it finds a list, the function value is
F –false.
To see how we could
arrive at a value of “falsconsider the next few questions.”
since the list L contains
a S-expression that is a list.
question.
In this case, L is not the null list,
so we ask the next question.
not an atom, then ask
the next question. In this case,
(CAR L) is an atom, so we want to check if the rest of the list L
is
composed
only of atoms.
with L replaced by (CDR
L).
question.
In this case, L is not the null list, so we
move to the next question.
not an atom, then
ask the next question. In this case,
(CAR L) is not an atom, so we ask the next question.
because the question T is
always true!
If T is true --- as it always
is --- then the value of the function is F --- false.
description of the function. We call
these “aggravation parentheses”,
and they are always put at the end of a function.
“(ISLAT L) looks at each
S-expression in its argument to see if it is an atom. If it runs out of
S-expressions before it finds
a
list, the value of
(ISLAT L) is T. if it finds
a list as it did in the example (BACON (AND EGGS) ), the value of (ISLAT
L) is F”.
Because one of the atoms
of the LAT (COFFEE TEA OR MILK) is the same as the atom A, TEA.
Since A is not one of the
atoms of the LAT.
because the atom MEAT is
one of the atoms of the LAT (MASHED POTATOES AND MEAT GRAVY)
Hint: write down the function
(MEMBER A LAT), and refer to it while you work on the next group of questions.
Note: This is also
the first question asked by (ISLAT L).
found
in the LAT. If it is not,then we ask the next question.
In this case, it is not null, so we ask the next question.
is not, then
we ask the next question. In this case,
it is not, so we ask the next question.
T is question whose
answer is always true.
“what color is an orange?”.
find out if the atom A
is somewhere in the rest of
the LAT. The function does this by referring us back to the
original
function,
with the argument LAT replaced by (CDR LAT).
Remember Commandment No.
1