Overview Clamps Packages CM Dictionary Clamps Dictionary Fomus
Next: Defining relations , Previous: A short example , Up: cl-refs , Home: General

Clamps Packages

The ref-object class

To make this task less challenging, cl-refs separates the definition of the variables and the application logic into distinct parts, automating the updating of variables behind the scenes. This makes the maintenance of the program much easier1.

For a variable with possible relations to other variables, cl-ref uses a special class called ref-object. Three main functions are defined to create and access a ref-object: A creation function, a reader function and a setter function. These functions are always the same, regardless of the variable they apply to, so there is no need to define a new function for setting any of the variables as in the example in the previous section.

creation function

A ref-object gets created with the function make-ref:

(defparameter v1 (make-ref 1.0)) ; => v1

v1 ; => #<ref 1.0>
reader function

To read the value of a ref-object, use the function get-val:

(get-val v1)  ; => 1.0
setter function

To set the value of a ref-object, use the function set-val:

(set-val v1 2.3)  ; => 2.3

(get-val v1) ; => 2.3

Footnotes:

1

The implementation ideas are similar to javascript frameworks which became increasingly popular in the 2010s like React or Vue.js, although they are rooted in much older concepts from the 1970s and 80s.