Reference: PLT Scheme

1`` | Language Model
2`` | Syntactic Forms
3`` | Datatypes
4`` | Structures
5`` | Classes and Objects
6`` | Units
7`` | Contracts
8`` | Pattern Matching
9`` | Control Flow
10`` | Concurrency
11`` | Macros
12`` | Input and Output
13`` | Reflection and Security
14`` | Operating System
15`` | Memory Management
16`` | Running PLT Scheme
| Bibliography
| Index

On this page:

struct-copy

Version: 4.0.2
contents index
← prev up next →

#### 4.4`` Copying and Updating Structures

(struct-copy id struct-expr [field-id expr] ...)

Creates a new instance of the structure type id with the same field values as the structure produced by struct-expr, except that the value of each supplied field-id is instead determined by the corresponding expr.

The id must have a transformer binding that encapsulates information about a structure type (i.e., like the initial identifier bound by define-struct), and the binding must supply a constructor, a predicate, and all field accessors.

Each field-id is combined with id to form id-field-id (using the lexical context of field-id), which must be one of the accessor bindings in id. The accessor bindings determined by different field-ids must be distinct. The order of the field-ids need not match the order of the corresponding fields in the structure type.

The struct-expr is evaluated first. The result must be an instance of the id structure type, otherwise the exn:fail:contract exception is raised. Next, the field exprs are evaluated in order (even if the fields that correspond to the field-ids are in a different order). Finally, the new structure instance is created.

The result of struct-expr can be an instance of a sub-type of id, but the resulting copy is an immediate instance of id (not the sub-type).

contents index
← prev up next →