XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

&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 are removed.

Examples

(defun my-add                            ; define function MY-ADD
  (num1 &rest num-list &aux sum)         ;   with 1 arg, rest, 1 aux var
  (setq sum num1)                        ;   clear SUM
  (dotimes (i (length num-list) )        ;   loop through rest list
     (setq sum (+ sum (car num-list)))   ;      add the number to sum
     (setq num-list (cdr num-list)))     ;      and remove num from list
  sum)                                   ;   return sum when finished

(my-add 1 2 3 4)                         ; returns 10
(my-add 5 5 5 5 5)                       ; returns 25

(defun more-keys                         ; define MORE-KEYS
        ( a                              ;   with 1 parameter A
          &aux b                         ;   with local var B
               (c 99)                    ;        local var C= 99
               (d T)  )                  ;        local var D= T
        (format T "a=~a " a)             ;   body of the function
        (format T "b=~a " b)
        (format T "c=~a " c)
        (format T "d=~a " d))

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

See the &aux keyword in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next