Lecture overview -- Keyboard shortcut: 'u'  Previous page: Imperative Scheme Constructs -- Keyboard shortcut: 'p'  Next page: String mutators -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Lecture 9 - Page 3 : 6
Functional Programming in Scheme
Imperative programming in Scheme
List mutators

Besides the list constructor cons and the list selectors car and cdr there are also list mutators called set-car! and set-cdr!

  • The list mutator procedures:

    • The command (set-car! x y) changes the value of the car position of the cons cell referred by x. The car position is assigned to y

    • The command (set-cdr! x y) changes the value of the cdr position of the cons cell referred by x. The cdr position is assigned to y

    • Using the list mutators it is possible to make circular structures

Without use of the list mutators, and with use of structural equivalence predicates, it is not possible to tell the difference between a list structure and a copy of the list structure
If we make use of list mutators we can tell the difference between a list structure, LS, and a copy of LS. The way to do it is to mutate LS and observe that the copy is not changed. Using only the functional subset of Scheme (and disregarding the very discriminating equality predicates such as eq? and eqv?) a copy of LS serves the same purposes as LS itself.