Theme index -- Keyboard shortcut: 'u'  Previous theme in this lecture -- Keyboard shortcut: 'p'  Next slide in this lecture -- Keyboard shortcut: 'n'Expressions, Types, and Functions
7.  Other Data Types

There are other kinds of data than lists and numbers. In this chapter we will - relatively briefly - review booleans, characters, symbols, vectors, and strings in Scheme.

7.1 Other simple types7.3 Strings
7.2 Vectors
 

7.1.  Other simple types
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

As most other programming languages Scheme supports the simple types of booleans and characters. As a slightly more specialized type, Scheme also supports symbols.

You can get the details of these data types by reading in the Scheme Report [Abelson98]. Section 6.3.1 in the report covers the boolean type. Section 6.3.4 is about characters. Symbols are described in section 6.3.3. From the slide and the annotated slide view of this material, there are direct links to these sections of the Scheme Report.

Besides numbers, Scheme also supports booleans, characters, and symbols

  • Booleans

    • True is denoted by #t and false by #f

    • Every non-false values count as true in if and cond

  • Characters

    • Characters are denoted as #\a, #\b, ...

    • Some characters have symbolic names, such as #\space, #\newline

  • Symbols

    • Symbols are denoted by quoting their names: 'a , 'symbol , ...

    • Two symbols are identical in the sense of eqv? if and only if their names are spelled the same way

The equivalence function eqv? is similar to eq?. See section 6.1 of [Abelson98] for details.

 

7.2.  Vectors
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

There are a number of superficial similarities between vectors and list, as supported by Scheme. However, at the conceptual level vectors are arrays, and lists are linearly linked structures. As such, they represent quite different structures.

The most basic and fundamental difference between lists and vectors is that lists can be changed and extended in a very flexible way (due to the use of dynamically allocated cons cells). A vector is of fixed and constant size once allocated.

Vectors are treated in section 6.3.6 of [Abelson98].

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

 

7.3.  Strings
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

There are no big surprises in the way Scheme handles and supports strings. Please see section 6.3.5 of [Abelson98] for details.

String is an array-like data structure of fixed size with elements of type character.

  • The string and vector types have many similar functions

  • A number of functions allow lexicographic comparisons of strings:

    • string=?, string<?, string<=?, ...

    • There are case-independent, ci, versions of the comparison functions.

  • The substring function extracts a substring of a string

Like lists, strings are important for many practical purposes, and it is therefore important to familiarize yourself with the string functions in Scheme

 

7.4.  References
[Abelson98]Richard Kelsey, William Clinger and Jonathan Rees, "Revised^5 Report on the Algorithmic Language Scheme", Higher-Order and Symbolic Computation, Vol. 11, No. 1, August 1998, pp. 7--105.

Generated: Tuesday July 2, 2013, 09:14:51
Theme index -- Keyboard shortcut: 'u'  Previous theme in this lecture -- Keyboard shortcut: 'p'  Next slide in this lecture -- Keyboard shortcut: 'n'