From: Arnold Putong
Subject: Help: Variable number of arguments
Date: 
Message-ID: <Pine.LNX.3.91.960802143011.696A-100000@apollo.engg.upd.edu.ph>
How does one define a function that can take a variable number of arguments
in LISP.  Is there a better method other than making the argument 
to be explicitly a list.


Thanks,
Arnold Putong
email: ······@apollo.engg.upd.edu.ph

From: Stefan Bamberger
Subject: Re: Help: Variable number of arguments
Date: 
Message-ID: <bambi-0208961655360001@wi6a84.informatik.uni-wuerzburg.de>
In article
<······································@apollo.engg.upd.edu.ph>, Arnold
Putong <······@apollo.engg.upd.edu.ph> wrote:

> How does one define a function that can take a variable number of arguments
> in LISP.  Is there a better method other than making the argument 
> to be explicitly a list.
> 
> 
> Thanks,
> Arnold Putong
> email: ······@apollo.engg.upd.edu.ph

You have two possibilities:

1.) Use optional parameters
2.) Use key parameters

The difference between both is that with the first the order is important
whereas with the second it isn't.

examples:

(defun foo (a1 &optional a2 a3)
  `(,a1 ,a2 ,a3)
 )

(foo 23 2 3) -> (23 2 3)
(foo 23)     -> (23 nil nil)

You have no chance only to specify a1 and a3. The second argument will
always correspond to a2!


(defun bar (b1 &key b2 b3)
 `(,b1 ,b2 ,b3)
  )

(bar 23 :b2 2 :b3 3)  -> (23 2 3)
(bar 23)              -> (23 nil nil)

Now, you can specify which argument you want to support
(bar 23 :b3 4)        -> (23 nil 4)

See CLtL2 for further details how to use optional and key parameters

If you don't know at evaluation time with how many arguments your function
will be appllied, use the &rest statement.
It will make automatically a list of all you arguments.
You can combine &optional,&key and &rest to achieve really tricky argument
setting behaviour

(defun foobar (&rest args)
 args)

(foobar 23 2 3 :b30 222)  -> (23 2 3 :b30 222)


- stefan
From: Thomas A. Russ
Subject: Re: Help: Variable number of arguments
Date: 
Message-ID: <ymispa165t6.fsf@hobbes.isi.edu>
Use &optional, &rest and/or &keyword in the lambda list.

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Leo Sarasua
Subject: Re: Help: Variable number of arguments
Date: 
Message-ID: <32068A3C.58CA@bart.nl>
Arnold Putong wrote:
> 
> How does one define a function that can take a variable number of arguments
> in LISP.  Is there a better method other than making the argument
> to be explicitly a list.How about:
 (defun foo (&rest arguments)
    (do-something (car arguments))
    (if (cdr arguments) (print "There are still more arguments")))