A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://docs.racket-lang.org/reference/structutils.html below:

5.6 Structure Utilities

5.6 Structure Utilities🔗ℹ

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-v

for a field that is not accessible. A single

opaque-v

value is used in the vector for contiguous inaccessible fields. (Consequently, the size of the vector does not match the size of the

struct

if more than one field is inaccessible.)

Returns

#t

if

struct-info

exposes any structure types of

v

with the current inspector,

#f

otherwise.

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

#f

if

v

is not an instance of a

prefab

structure type. Otherwise, the result is the shorted key that could be used with

make-prefab-struct

to 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

prefab

structure type, using the

v

s as field values. The

key

and the number of

v

s determine the

prefab

structure type.

A key identifies a structure type based on a list with the following items:

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

#t

if

v

can be a

prefab

structure type key,

#f

otherwise.

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-write

or

prop:custom-write

. The function prints values in “constructor style.” When the value is

print

ed 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

write

mode 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