Start DrScheme. Call the cons procedure to create a list that has
the number 1 as its first and only element.
Describe the value of the expression
(cons 'alpha (cons 'beta (cons 'gamma (cons 'delta null))))
and check your answer by asking DrScheme to evaluate this expression.
Call the procedure list, supplying the numerals 17 and 43 as operands. Describe the value returned by the procedure.
How would you call the list procedure to create a list containing
the symbols alpha, beta, and gamma, in that order?
How would you invoke the list procedure to create an empty list?
Is it possible to create a list in which the same element occurs more than once? Find out by experiment.
What is the cdr of a one-element list?
It makes no sense to apply the car and cdr procedures to an
empty list, because there's no way to split off the ``first element'' of a
list that has no elements. What happens if you try it anyway? Find out by
having DrScheme evaluate a deliberately incorrect procedure call.
Use Scheme to give the name Greek-letters to the list constructed by
the expression (list 'alpha 'beta (list 'gamma-1 'gamma-2) 'delta).
Then call the length procedure to confirm that it has four elements.
Determine the length of the empty list.
Write a Scheme procedure call to create a list of length 5. (For this exercise, I don't care what elements you put into the list.) Check your answer by having Scheme compute the length of that list.
Use Scheme to compute the reversal of the list whose elements are the
symbols senior, junior, second-year, and first-year, in that order.
If a list has another list as one of its elements, does reverse
reverse that inner list as well as the outer one? Find out by experiment.
Use Scheme to find the result of stringing together a list with the symbols
alpha and beta as its elements and a list with the numbers 1,
2, and 3 as its elements. How many elements does the resulting list have?
Invoke the procedure list, applying it to the two lists that you
strung together in exercise 14: a list with the symbols alpha and
beta as its elements and a list with the numbers 1, 2, and 3 as its
elements. How many elements does the resulting list have? The answer to
this question is different from the answer to the question at the end of
exercise 14 -- why?
Write a call to the procedure cons, applying it to our favorite two
lists: a list with the symbols alpha and beta as its elements
and a list with the numbers 1, 2, and 3 as its elements. How many elements
does the resulting list have? Why is the answer to this question different
from the answers to the questions at the end of exercises 14 and 15?
Write a call to the list-ref procedure that will extract the fourth
element of the list (38 72 apple -1/3 sample) -- namely, the number
-1/3.
I am indebted to Professor Ben Gum for his contributions to the development of this lab.