We have already seen several functions that can take a variable number of arguments, such as + or min. Some Lisp implementations allow such an argument list to be specified using dot notation.
(define (min1 n . others) (min1b n others))
(define (min1b n others)
(if (null? others)
n
(min1b (if (< (car others) n)
(car others)
n)
(cdr others)) ) )
> (min1 0)
0
> (min1 17 22 4 37 99 2 55)
2
In the function min1, the variable n is bound to the first
argument, while others is bound to a list of the remaining
arguments. min1 calls a tail-recursive function min1b to
do the work.
Contents    Page-10    Prev    Next    Page+10    Index