From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: Argument-list in function with variable number of arguments... Date: Fri, 20 May 2005 17:00:59 +0200 Organization: [posted via Easynet Spain] Message-ID: <87sm0igcwk.fsf@thalassa.informatimago.com> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1116601411 19783 80.91.229.2 (20 May 2005 15:03:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 20 May 2005 15:03:31 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri May 20 17:03:19 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DZ912-00060K-M9 for geh-help-gnu-emacs@m.gmane.org; Fri, 20 May 2005 17:02:20 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DZ93u-0007Oh-7x for geh-help-gnu-emacs@m.gmane.org; Fri, 20 May 2005 11:05:18 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!feed.news.tiscali.de!newsfeed.tiscali.ch!feed1.news.be.easynet.net!easynet-monga!easynet.net!easynet-post2!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:FhZ5tfP8I2y6WV7266c0ouuADmA= Original-Lines: 46 Original-NNTP-Posting-Host: 62.93.174.79 Original-X-Trace: DXC=GO4LEOb3bko8`[oeVJEXhgEY<>`XO4V7m>Uh List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:26856 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:26856 luca.spinacci@seleniacomms.com writes: > 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") > ) > > 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 > First : first_argument > Second : second_argument > Third : third_argument > ...and so on without knowing their number in advance. > > Is it possible? > Thank you very much, > Luca. Yes. C-h f interactive RET "If the argument is not a string, it is evaluated to get a list of arguments to pass to the function." So: (require 'cl) (defun my-command (&rest arguments) (interactive (loop while (y-or-n-p "Another argument? ") collect (read-from-minibuffer "Next argument: "))) (insert (format "%S" arguments))) -- __Pascal Bourguignon__ http://www.informatimago.com/ Kitty like plastic. Confuses for litter box. Don't leave tarp around.