[an error occurred while processing this directive]

cs150: Notes 6

Assignments Due

Notes and Questions

Is it better to solve problems by thinking about what we need to do to solve the problem (procedures) or by thinking about what we need to represent to solve the problem (data)?









What does cons do?



What do car and cdr do?



What is the value of (car (cdr (cons 1 (cons 2 (cons 3 null)))))?


Why do we need the special list null?

Are there any data structures that cannot be built using just cons?









How could we define cons, car and cdr if Scheme did not have them as primitives?





A list is either (1) null or (2) a pair where the second part of the pair is a list. To define procedures on lists, we need to handle both cases: what do we do when the list is null and what do we do when the list is a pair.

Define length a procedure that takes a list as its operand and evaluates to the number of elements in that list.
















cs1120: Computer Science
University of Virginia
weimer@virginia.edu
Using these Materials