25 Structs

▼ |  | Unstable

1 | Guidelines for developing unstable libraries
2 | Bytes
3 | Classes and Objects
4 | Contracts
5 | Definitions
6 | Dictionaries
7 | Directories
8 | Exceptions
9 | Filesystem
10 | Functions
11 | Lists
12 | Net
13 | Path
14 | PLane T Packages
15 | Ports
16 | Pretty-Printing
17 | Regular Expressions
18 | Requiring Modules
19 | Sandboxed Evaluation
20 | Scribble Documentation
21 | Sets
22 | S-Expression Diff
23 | Source Locations
24 | Strings
25 | Structs
26 | Syntax
27 | Planet Package Macros
28 | Text Representations
29 | Multiple Values
30 | XML and CSS
31 | Polymorphic Contracts
32 | Finding Mutated Variables
33 | Find
34 | Interface-Oriented Programming for Classes
35 | Sequences
36 | Hash Tables
37 | Match
38 | Generics
39 | Mark Parameters
40 | Debugging
41 | Contracts for macro subexpressions
42 | GUI libraries

On this page:

make
struct->list

Version: 5.0.1.5
top← prev up next →

### 25`` Structs

Ryan Culpepper <ryanc@racket-lang.org>

( require unstable/struct)

This library is unstable; compatibility will not be maintained. See Unstable for more information.

( make struct-id expr ...)

Creates an instance of struct-id, which must be bound as a struct name. The number of exprs is statically checked against the number of fields associated with struct-id. If they are different, or if the number of fields is not known, an error is raised at compile time.

Examples:
> ( define-struct triple (a b c))
> ( make triple 3 4 5)
#<triple>
> ( make triple 2 4)
eval:4:0: make: wrong number of arguments for struct triple
(expected 3, got 2) in: (make triple 2 4)

( struct->list v [#:on-opaque on-opaque]) → ( or/c list? #f)
v : any/c
on-opaque : ( or/c 'error 'return-false 'skip) = 'error

Returns a list containing the struct instance v’s fields. Unlike struct->vector, the struct name itself is not included.

If any fields of v are inaccessible via the current inspector the behavior of struct->list is determined by on-opaque. If on-opaque is 'error (the default), an error is raised. If it is 'return-false, struct->list returns #f. If it is 'skip, the inaccessible fields are omitted from the list.

Examples:
> ( define-struct open (u v) #:transparent)
> ( struct->list (make-open 'a 'b))
'(a b)
> ( struct->list #s(pre 1 2 3))
'(1 2 3)
> ( define-struct (secret open) (x y))
> ( struct->list (make-secret 0 1 17 22))
struct->list: expected argument of type <non-opaque
struct>; given (secret 0 1 ...)
> ( struct->list (make-secret 0 1 17 22) #:on-opaque 'return-false)
#f
> ( struct->list (make-secret 0 1 17 22) #:on-opaque 'skip)
'(0 1)
> ( struct->list 'not-a-struct #:on-opaque 'return-false)
#f
> ( struct->list 'not-a-struct #:on-opaque 'skip)
'()

top← prev up next →