Next: , Previous: , Up: lang   [Index]


1.6 Defining storage locations

The library (vicare language-extensions variables) provides a way to define simple storage locations similar to the variables used in many languages. The variable type is disjoint from the other types.

The following bindings are exported by the library (vicare language-extensions variables); the bindings whose name is prefixed with $ are unsafe operations: they do not validate their arguments before accessing them.

Function: make-variable
Function: make-variable obj

Build and return a new variable object. The variable is initialised to obj, which defaults to the return value of (void).

Function: variable? obj

Return #t if obj is a variable object, else return #f.

Function: variable-set! variable obj
Function: variable-ref variable
Function: $variable-set! variable obj
Function: $variable-ref variable

Setter and getter for the value of variable objects.

Syntax: define-variable ?name
Syntax: define-variable ?name obj
Syntax: define-variable (?name . ?formals) ?body

Like define, but store the value in a newly built variable object, which is then bound to ?name. Example:

(import (vicare)
  (vicare language-extensions variables))

(define-variable v 123)
v ⇒ 123
(set! v 456)
v ⇒ 456

While define defines a binding which, when exported by a library, cannot be modified, define-variable allocates a storage location, so the value bound to ?name can be modified at will.

Syntax: define-variable-alias ?name ?variable-expr
Syntax: $define-variable-alias ?name ?variable-expr

Like the second form of define-variable, but accept as second argument an expression which, when evaluated, returns a variable object.