1. Robert Smith
  2. cl-ref

Overview

HTTPS SSH
CL-REF is a library for mutable, pointer-like references.

We can use REFs to emulate "pass-by-reference" functions.

CL-USER> (defun square (x)
           (setf (cl-ref:deref x)
                 (expt (cl-ref:deref x) 2))
           (values))
SQUARE

CL-USER> (defvar x (cl-ref:ref 5))
X

CL-USER> (square x)
; No value

CL-USER> (cl-ref:deref x)
25

The package exports:

  REF : <type> The type of a REF object
      : <fn>   A function to construct a REF object
  REF-P : <fn> Decide if an object is a REF.
  DEREF : <fn> Obtain the value referenced by a REF.
  
We also have a setf function for DEREF.