Fundamentals of Computer Science I (CS151 2003F)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Guidelines for Lab Writeups]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Scheme Report]
[Glimmer Scheme Reference]
[CSC151.01 (Gum)]
[CSC151 2003S]
[CSC151 2002F]
[SamR]
Summary:
In this laboratory, you will further ground your understanding of what happens behind the scenes
when Scheme deals with lists and other pair-based structures.
Useful procedures:
cons,
null?, and
pair?
Contents:
a. Review the reading on pairs and pair structures.
b. Start DrScheme.
Draw box-and-pointer diagrams for each of the following lists:
((x) y z)
(x (y z))
((a) b (c ()))
Enter each of the following expressions into Scheme. In each case, explain why Scheme does or does not use the dot notation when displaying the value.
(cons 'a "Walker")
(cons 'a null)
(cons 'a "null")
(cons 'a "()")
(cons null 'a)
(cons null (cons null null))
Draw a box-and-pointer representation of the value of the last two expressions in the previous exercise.
What do you think that pair? will return for each of
the following? How about list?. Confirm you answer
experimentally and explain any that you found particularly tricky.
(cons 'a 'b)
(cons 'a (cons 'b 'c))
(cons 'a null)
null
(list 'a 'b 'c)
(list 'a)
(list)
You may recall that I told you that many kinds of data are defined recursively. For example, a list is either (1) null or (2) cons of anything and a list.
Using that recursive
definition of lists, write a procedure,
(listp? val), that determines whether
or not val is a list.
You may not use list? in your definition of
listp?.
If you were able to complete the primary exercises with time to spare, you might want to consider the following problems:
listp?
Write listp? without using if or cond.
Write a procedure, (last pairthing) that finds the last
value in a list-like sequence of pairs. If the sequence of pairs is actually a list, return the last element of the list. If the sequence of pairs ends with a pair, return the cdr of that pair.
In solving this problem you should only step through the list once.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/History/Labs/pairs.html.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Guidelines for Lab Writeups]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Scheme Report]
[Glimmer Scheme Reference]
[CSC151.01 (Gum)]
[CSC151 2003S]
[CSC151 2002F]
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue Dec 9 13:59:15 2003.
The source to the document was last modified on Mon Oct 13 13:51:00 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003F/Labs/pairs.html.
;
;
Check with Bobby