Data and Aggregate Types

Choose lists, pairs, vectors, and bytevectors, then read their contents and learn which values you can change.

Use a list for a sequence, a pair for two linked values, or a vector for elements you access by index. This page shows how to build those values and which ones you can change.

Recognize the value types

Paste each example into the playground and run it.

LISPEX
(list (vector? #(1 2)) (bytevector? #u8(1 2)) (pair? (cons 1 2)))

Result

OUTPUT
(#t #t #t)

The three procedures ask whether each value is a vector, a bytevector, or a pair. Each returns #t, meaning true.

Pairs, vectors, strings, and bytevectors are aggregate values. They hold other values, characters, or bytes.

Build a list or a pair

LISPEX
(list (cons 1 (list 2 3)) (cons 1 2) (list? (cons 1 2)))

Result

OUTPUT
((1 2 3) (1 . 2) #f)

cons makes a pair from two values. When the second value is a list, cons adds the first value to its front. Thus (cons 1 (list 2 3)) produces (1 2 3).

A proper list is either the empty list () or a chain of pairs ending in (). The pair (cons 1 2) ends in 2 instead. It prints as (1 . 2), and list? returns #f.

A chain that loops back on itself is also not a proper list. equal? can compare cyclic structures and still finish.

Choose a value

ValueExampleUse and changes
boolean, number, character, symbol#t, 42, 2/3, 2.0, #\a, 'nameindividual values, called atoms
empty list'()ends a proper list
list / pair(list 1 2), (cons 1 2)sequence / two linked values; pairs are immutable
string"hello"text; immutable
vector made by a procedure(vector 1 2)indexed elements; you can replace them with vector-set!
literal vector#(1 2)indexed elements; immutable
bytevector#u8(1 2)fixed-length block of bytes; immutable
procedure(lambda (x) x)callable value; its body is not data you can inspect
escape continuationproduced by call/ccreturns control to a saved point; see Continuations

Immutable means you cannot replace the stored contents. Quoted aggregate data is immutable too. To change a vector's elements, use vector or make a mutable copy with vector-copy.

A variable can refer to a different value after set!. This changes the variable's stored value, not the contents of the old value.

Fill a data template

Quasiquote lets you write a template and fill selected positions with computed values.

LISPEX
(define x 7)
(define ys (list 2 3))

`(a ,x ,@ys b)

Result

OUTPUT
(a 7 2 3 b)

The backtick starts the template. ,x inserts the value of x. ,@ys inserts the elements of the list ys, one after another.

Splicing with ,@ works in element positions within a quasiquoted list or vector. Using it outside quasiquote or where a single value is required produces E130.

Supported types

The current language profile, the set of supported language features, includes the values above. Complex numbers, ports, records, and mutable pairs or strings are not supported.

Internal evaluation results, control signals, and markers for variables awaiting initialization remain inside the runtime. Programs cannot store them as ordinary values.

Equality and object identity explains how to compare contents or ask whether two names refer to the same object. List and aggregate procedures covers construction, access, and changes.