Nyquist / XLISP 2.0  -  Contents | Tutorials | Examples | Reference

&aux


Type:   -   keyword
Source:   -   xleval.c

Syntax

&aux [aux-var | (aux-var aux-value)] ...
aux-var - auxiliary variable
aux-value - auxiliary variable initialization

Description

In XLISP, there are several times that you define a formal argument list for a body of code [like defun, defmacro, :answer and lambda]. The 'aux-var' variables are a mechanism for you to define variables local to the function or operation definition. If there is an optional 'aux-value', they will be set to that value on entry to the body of code. Otherwise, they are initialized to NIL. At the end of the function or operation execution, these local symbols and their values are removed.

Examples

A function 'my-add' with one required argument 'num1', one &rest argument 'num-list', and one &aux variable 'sum':

(defun my-add (num1 &rest num-list &aux sum)
  (setq sum num1)          ; initialize SUM
  (dolist (i num-list)     ; loop through the num-list
    (setq sum (+ sum i)))  ; add each number to SUM
  sum)                     ; return SUM when finished

(my-add 1 2 3 4)    => 10
(my-add 5 5 5 5 5)  => 25

See  + , defun, dolist, &rest, setq.

A function 'more-keys' with one required argument 'a' and three &aux variables 'b' [initialized to NIL], 'c' [initialized to 99], and 'd' [initialized to  T ]:

(defun more-keys (a &aux b (c 99) (d t))
  (format t "a=~a b=~a c=~a d=~a~%" a b c d))

> (more-keys "hi")
a=hi b=NIL c=99 d=T
NIL

See defun, format.

See also:

  Back to Top


Nyquist / XLISP 2.0  -  Contents | Tutorials | Examples | Reference