In XLISP, there are several times that you define a formal argument list
for a body of code like
(defun foo ; define function FOO
(a b &optional c d &rest e) ; with some of each argument
(print a) (print b)
(print c) (print d) ; print out each
(print e))
(foo) ; error: too few arguments
(foo 1) ; error: too few arguments
(foo 1 2) ; prints 1 2 NIL NIL NIL
(foo 1 2 3) ; prints 1 2 3 NIL NIL
(foo 1 2 3 4) ; prints 1 2 3 4 NIL
(foo 1 2 3 4 5) ; prints 1 2 3 4 (5)
(foo 1 2 3 4 5 6 7 8 9) ; prints 1 2 3 4 (5 6 7 8 9)
(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
See the
&rest
keyword in the