► |  | How to Design Programs Languages

1 | Beginning Student
2 | Beginning Student with List Abbreviations
3 | Intermediate Student
4 | Intermediate Student with Lambda
5 | Advanced Student
| Index

▼ | 1 | Beginning Student

1.1 | define
1.2 | define-struct
1.3 | Function Calls
1.4 | Primitive Calls
1.5 | cond
1.6 | if
1.7 | and
1.8 | or
1.9 | Test Cases
1.10 | empty
1.11 | Identifiers
1.12 | Symbols
1.13 | true and false
1.14 | require
1.15 | Primitive Operations

On this page:

define-struct

top ← prev up next →

#### 1.2`` define-struct

( define-struct structid (fieldid ...))

Define a new type of structure. The structure’s fields are named by the fieldids in parentheses. After evaluation of a define-struct form, a set of new primitives is available for creation, extraction, and type-like queries:

- make-structid : takes a number of arguments equal to the number of fields in the structure type, and creates a new instance of the structure type.

- structid-fieldid : takes an instance of the structure and returns the field named by structid.

- structid? : takes any value, and returns true if the value is an instance of the structure type.

- structid : an identifier representing the structure type, but never used directly.

The created names must not be the same as a primitive or another defined name.

top ← prev up next →