notes21 - Big idea: abstract data type sequence (or list )....

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Big idea: abstract data type sequence (or list ). We want to represent an ordered sequence of things. (They can be any kind of things.) We implement sequences using pairs, with each car pointing to an element and each cdr pointing to the next pair. What should the constructors and selectors be? The most obvious thing is to have a constructor list that takes any number of arguments and returns a list of those arguments, and a selector nth that takes a number and a list as arguments, returning the n th element of the list. Scheme does provide those, but it often turns out to be more useful to select from a list diFerently, with a selector for the ±rst element and a selector for all the rest of the elements (i.e., a smaller list). This helps us write recursive functions such as the mapping and ±ltering ones we saw for sentences earlier. Since we are implementing lists using pairs, we ought to have specially-named constructors and selectors for lists, just like for rational numbers:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/17/2010 for the course COMPUTER S 26275 taught by Professor Harvey,b during the Spring '10 term at University of California, Berkeley.

Ask a homework question - tutors are online