Creates a vector representing
v. The first slot of the result vector contains a symbol whose printed name has the form
struct:id. Each remaining slot contains either the value of a field in
v, if it is accessible via the current inspector, or
opaque-vfor a field that is not accessible. A single
opaque-vvalue is used in the vector for contiguous inaccessible fields. (Consequently, the size of the vector does not match the size of the
structif more than one field is inaccessible.)
Returns
#tif
struct-infoexposes any structure types of
vwith the current inspector,
#fotherwise.
Typically, when (struct? v) is true, then (struct->vector v) exposes at least one field value. It is possible, however, for the only visible types of v to contribute zero fields.
Returns #t if v is a structure type descriptor value, #f otherwise.
Returns
#fif
vis not an instance of a
prefabstructure type. Otherwise, the result is the shorted key that could be used with
make-prefab-structto create an instance of the structure type.
Examples:
> (prefab-struct-key #s(cat "Garfield"))'cat
> (struct cat (name) #:prefab) > (struct cute-cat cat (shipping-dest) #:prefab) > (cute-cat "Nermel" "Abu Dhabi")'#s((cute-cat cat 1) "Nermel" "Abu Dhabi")
> (prefab-struct-key (cute-cat "Nermel" "Abu Dhabi"))'(cute-cat cat 1)
Creates an instance of a
prefabstructure type, using the
vs as field values. The
keyand the number of
vs determine the
prefabstructure type.
A key identifies a structure type based on a list with the following items:
A symbol for the structure type’s name.
An exact, nonnegative integer representing the number of non-automatic fields in the structure type, not counting fields from the supertype (if any).
A list of two items, where the first is an exact, nonnegative integer for the number of automatic fields in the structure type that are not from the supertype (if any), and the second element is an arbitrary value that is the value for the automatic fields.
A vector of exact, nonnegative integers that indicate mutable non-automatic fields in the structure type, counting from 0 and not including fields from the supertype (if any).
Nothing else, if the structure type has no supertype. Otherwise, the rest of the list is the key for the supertype.
An empty vector and an auto-field list that starts with 0 can be omitted. Furthermore, the first integer (which indicates the number of non-automatic fields) can be omitted, since it can be inferred from the number of supplied vs. Finally, a single symbol can be used instead of a list that contains only a symbol (in the case that the structure type has no supertype, no automatic fields, and no mutable fields).
The total field count must be no more than 32768. If the number of fields indicated by key is inconsistent with the number of supplied vs, the exn:fail:contract exception is raised.
Examples:
Added in version 8.5.0.8 of package base.
If the number of fields indicated by key is inconsistent with field-count, the exn:fail:contract exception is raised.
Return
#tif
vcan be a
prefabstructure type key,
#fotherwise.
See make-prefab-struct for a description of valid key shapes.
5.6.1 Additional Structure Utilities🔗ℹProduces a function suitable as a value for
gen:custom-writeor
prop:custom-write. The function prints values in “constructor style.” When the value is
printed as an expression, it is shown as an application of the constructor (as returned by
get-constructor) to the contents (as returned by
get-contents). When given to
write, it is shown as an unreadable value with the constructor separated from the contents by a colon.
Examples:
> (print (point 1 2))(point 1 2)
> (write (point 1 2))#<point: 1 2>
The function also cooperates with pretty-print:
#<point:
3000000
4000000>
Note that the printer uses a separate property,
prop:custom-print-quotable, to determine whether a struct instance is quotable. If so, the printer may print it in
writemode it in certain contexts, such as within a list. For example:
> (print (list (point 1 2) (point 3 4)))'(#<point: 1 2> #<point: 3 4>)
> (print (list (point2 1 2) (point2 3 4)))(list (point 1 2) (point 3 4))
Keyword arguments can be simulated with unquoted-printing-string:
; Private implementation ; Public ``constructor'' > (define (kwpoint #:x x #:y y) (kwpoint-impl x y)) ; Example use > (print (kwpoint #:x 1 #:y 2))(kwpoint #:x 1 #:y 2)
> (write (kwpoint #:x 3 #:y 4))#<kwpoint: #:x 3 #:y 4>
Added in version 6.3 of package base.
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:
Added in version 6.3 of package base.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4