Previous: , Up: syntaxes   [Contents][Index]


5.10 Miscellaneous operations

Vicare allows us to specify special procedures for built–in Scheme types, record–types and label–types; they are:

Type predicates

When applied to a value the type predicate returns #t if the value matches the type; otherwise it returns #f. It is always possible to use the type predicate with the is-a? syntax, see is-a?.

Equality predicates

When applied to two values of the same type: the predicate returns #t if the values are equal; otherwise it returns #f.

Comparison procedures

When applied to two values A and B of the same type, the procedure returns a fixnum:

-1

If A is less than B.

0

If A is equal to B.

+1

If A is greater than B.

Hash functions

When applied to an instance of the type: compute and return a non–negative fixnum suitable to be used by hashtables.

The following syntactic bindings are exported by the library (vicare).

Macro: equality-predicate ?type

Return a function that can be used as equality predicate between instances of ?type, which must be a type annotation. If ?type itself has no equality predicate: traverse the hierarchy of parents in search of a predicate. If the hierarchy has no equality predicate: raise a syntax violation.

Macro: comparison-procedure ?type

Return a function that can be used as comparison procedure between instances of ?type, which must be a type annotation. If ?type itself has no comparison procedure: traverse the hierarchy of parents in search of a procedure. If the hierarchy has no comparison procedure: raise a syntax violation.

Macro: hash-function ?type

Return #f or a function that can be used as hash function for instances of ?type, which must be a type annotation. If ?type itself has no hash function: traverse the hierarchy of parents in search of a function. If the hierarchy has no hash function: raise a syntax violation.

Macro: hash ?expr

When the expander succeeds in determining the type of ?expr at expand–time: if there is a single return value, expand into an expression that computes and returns a hash value for the return value; otherwise raise a syntax violation.

When the expander fails to determine the type of ?expr at expand–time: expand into an expression that attempts, at run–time, to determine the type of the return value and compute and return a hash value for it.

The hash function used by this syntax is:


Previous: , Up: syntaxes   [Contents][Index]