variable length argument lists

Started by jsmall, September 21, 2004, 07:12:15 PM

Previous topic - Next topic

jsmall

Without resorting to define-macro and (args) what

is the preferred idiom for specifying a function

taking a variable number of arguments?



Do you simply have to anticipate these optional arguments?



     (define (foo x y z)  ...)



But if this is the case than passing this variable number

of arguments onto another such function such as a native

function is problematic.



     (define (foo x y z)  (+ x y z))   ;; no good if y or z is nil



Do I have to resort to prepacking my arguments into an array.



    (define (foo x optargs-list)

        (apply + (cons x optargs-list)))

Lutz

#1
What I do, is anticipate the number of vars i.e. (foo x y z) then I test i.e. (if y (...) (...)) etc. Variables which are not used will contain nil.



Sometimes I set those variables to a default i.e. (if (not y) (set 'y 0)) where '0' would be the default value.



In newLISP when you pass too much args they get simply ignored.



Lutz