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:

make-struct-type-property
struct-type-property?

Version: 4.0.2
contents index
← prev up next →

#### 4.3`` Structure Type Properties

A structure type property allows per-type information to be associated with a structure type (as opposed to per-instance information associated with a structure value). A property value is associated with a structure type through the make-struct-type procedure (see Creating Structure Types) or through the #:property option of define-struct. Subtypes inherit the property values of their parent types, and subtypes can override an inherited property value with a new value.

(make-struct-type-property name [guard])

→

struct-type-property?
procedure?
procedure?

name : symbol?
guard : (or/c procedure? false/c) = #f

Creates a new structure type property and returns three values:

- a structure type property descriptor, for use with make-struct-type and define-struct;

- a property predicate procedure, which takes an arbitrary value and returns #t if the value is a descriptor or instance of a structure type that has a value for the property, #f otherwise;

- an property accessor procedure, which returns the value associated with structure type given its descriptor or one of its instances; if the structure type does not have a value for the property, or if any other kind of value is provided, the exn:fail:contract exception is raised.

If the optional guard is supplied as a procedure, it is called by make-struct-type before attaching the property to a new structure type. The guard-proc must accept two arguments: a value for the property supplied to make-struct-type, and a list containing information about the new structure type. The list contains the values that struct-type-info would return for the new structure type if it skipped the immediate current-inspector control check (but not the check for exposing an ancestor structure type, if any; see Structure Inspectors).

The result of calling guard is associated with the property in the target structure type, instead of the value supplied to make-struct-type. To reject a property association (e.g., because the value supplied to make-struct-type is inappropriate for the property), the guard can raise an exception. Such an exception prevents make-struct-type from returning a structure type descriptor.

Examples:
> (define-values (prop:p p? p-ref) (make-struct-type-property 'p))

> (define-values (struct:a make-a a? a-ref a-set!)
(make-struct-type 'a #f 2 1 'uninitialized
(list (cons prop:p 8))))

> (p? struct:a)
#t
> (p? 13)
#f
> (define an-a (make-a 'x 'y))
> (p? an-a)
#t
> (p-ref an-a)
8

> (define-values (struct:b make-b b? b-ref b-set!)
(make-struct-type 'b #f 0 0 #f))

> (p? struct:b)
#f

(struct-type-property? v) → boolean?
v : any/c

Returns #t if v is a structure type property descriptor value, #f otherwise.

contents index
← prev up next →