Lecture overview -- Keyboard shortcut: 'u'  Previous page: Other simple types -- Keyboard shortcut: 'p'  Next page: Strings -- 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 2 - Page 28 : 46
Functional Programming in Scheme
Expressions, Types, and Functions

Vectors in Scheme are heterogeneous array-like data structures of a fixed size

  • Vectors are denoted in a similar way as list

    • Example: #(0 a (1 2 3))

    • Vectors must be quoted in the same way as list when their external representations are used directly

  • The function vector is similar to the function list

  • There are functions that convert a vector to a list and vice versa

    • vector->list

    • list->vector

The main difference between lists and vectors is the mode of access and the mode of construction

There is direct access to the elements of a vector. List elements are accessed by traversing a chain of references. This reflects the basic differences between arrays and linked lists.

The mode of construction for list is recursive, using the cons function. Lists are created incrementally: New elements can be created when needed, and prepended to the list. Vectors are allocated in one chunck, and cannot be enlarged or decreased incrementally.