[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Argument-list in function with variable number of arguments...
From: |
Kevin Rodgers |
Subject: |
Re: Argument-list in function with variable number of arguments... |
Date: |
Fri, 20 May 2005 09:15:33 -0600 |
User-agent: |
Mozilla Thunderbird 0.9 (X11/20041105) |
luca.spinacci@seleniacomms.com wrote:
> Is there a way to have a variable number of arguments in
> a function argument-list?
> I know how to write a function in which a fixed number of arguments
> is expected for ex.
>
> ( defun my-function ( first second )
> (interactive "sFirst : \nsSecond : ")
> (insert ""first"\n"
> ""second"\n")
> )
See the Lambda Expressions node of the Emacs Lisp manual.
> So I'm asked for "first" and for "second"...and my-function
> inserts the two of them in a buffer.
> I would like to have more arguments (let's say n) and being
> asked for them interactively, for instance:
> How many arguments? : 5 <Ret>
> First : first_argument <Ret>
> Second : second_argument <Ret>
> Third : third_argument <Ret>
> ...and so on without knowing their number in advance.
If you don't know how many there are, you can't name them individually.
(defun your-function (&rest argument-list)
(interactive
(let* ((n (read (read-from-minibuffer "How many arguments? ")))
(i 0)
(args '()))
(while (< i n)
(setq args
(cons (read-from-minibuffer (format "Argument %d: "
(setq i (1+ i))))
args)))
args))
...)
--
Kevin Rodgers