From: Asuka
Subject: &rest args
Date: 
Message-ID: <d000u5$jek$1@nsnmpen3-gest.nuria.telefonica-data.net>
Hi, I've got a function with n arguments. The point is that I need the name 
of each argument, how can I get it if its possible?


Thanx 

From: Barry Margolin
Subject: Re: &rest args
Date: 
Message-ID: <barmar-8E1254.16490628022005@comcast.dca.giganews.com>
In article <············@nsnmpen3-gest.nuria.telefonica-data.net>,
 "Asuka" <········@hotmail.com> wrote:

> Hi, I've got a function with n arguments. The point is that I need the name 
> of each argument, how can I get it if its possible?

If you're using &REST, as implied by your Subject line, then the 
individual arguments don't have names.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Asuka
Subject: Re: &rest args
Date: 
Message-ID: <d004fc$1jt$1@nsnmpen3-gest.nuria.telefonica-data.net>
"Barry Margolin" <······@alum.mit.edu> escribi� en el mensaje 
·································@comcast.dca.giganews.com...
> In article <············@nsnmpen3-gest.nuria.telefonica-data.net>,
> "Asuka" <········@hotmail.com> wrote:
>
>> Hi, I've got a function with n arguments. The point is that I need the 
>> name
>> of each argument, how can I get it if its possible?
>
> If you're using &REST, as implied by your Subject line, then the
> individual arguments don't have names.


Is there another way to define a function with n arguments, where I can work 
with the name of the arguments, even thought its an array?


>
> -- 
> Barry Margolin, ······@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***

Thank You 
From: John Thingstad
Subject: Re: &rest args
Date: 
Message-ID: <opsmxiyciupqzri1@mjolner.upc.no>
On Mon, 28 Feb 2005 23:03:13 +0100, Asuka <········@hotmail.com> wrote:

>
> Is there another way to define a function with n arguments, where I can  
> work
> with the name of the arguments, even thought its an array?
>
>
>>
>> --
>> Barry Margolin, ······@alum.mit.edu
>> Arlington, MA
>> *** PLEASE post questions in newsgroups, not directly to me ***
>
> Thank You
>
>

yes.
&key as in
(defun func (val &key (key-name default-val) ...)
Then refer to key-name as a normal variable.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Pascal Bourguignon
Subject: Re: &rest args
Date: 
Message-ID: <87ll98nvfy.fsf@thalassa.informatimago.com>
"Asuka" <········@hotmail.com> writes:

> "Barry Margolin" <······@alum.mit.edu> escribi� en el mensaje 
> ·································@comcast.dca.giganews.com...
> > In article <············@nsnmpen3-gest.nuria.telefonica-data.net>,
> > "Asuka" <········@hotmail.com> wrote:
> >
> >> Hi, I've got a function with n arguments. The point is that I need the 
> >> name
> >> of each argument, how can I get it if its possible?
> >
> > If you're using &REST, as implied by your Subject line, then the
> > individual arguments don't have names.
> 
> 
> Is there another way to define a function with n arguments, where I can work 
> with the name of the arguments, even thought its an array?

I'm still quite puzzled by your question...

Do you want a variable number of arguments or do you want exactly N arguments?

If you want to define a function with N argument, then just do it!

    (defun f (arg1 arg2 arg3 ... argN)
        ...)

and use the names _you_'ve given to each argument.

If you want to define a function with a variable number of arguments,
using &REST, what makes you think that there will exist N effective
arguments?

eg:

    (defun g (&rest args)
        (destructuring-bind (arg1 arg2 argN) args
            (print arg1)))

could fail when g is called as:
(g) -->
*** - The object to be destructured should be a list with 3 elements, not NIL.




-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.
From: Kaz Kylheku
Subject: Re: &rest args
Date: 
Message-ID: <1109658691.093800.93650@o13g2000cwo.googlegroups.com>
Asuka wrote:
> Hi, I've got a function with n arguments. The point is that I need
the name
> of each argument, how can I get it if its possible?

You are looking for &optional.  This lets you name the arguments, yet
allow the caller to omit some of them.

When the caller omits some optional arguments, they take on default
values. But there is a way to tell that they were omitted.

Here is a function of n parameters, where n is 2. The caller must
specify one argument, and an optional second one:

(defun fun (required-arg
            &optional (optional-arg 42 optional-arg-supplied))
   )

If the caller specifies the second argument, the variable
optional-arg-supplied will be bound to T. If the caller does not
specify the second argument, it will taken on the default value 42, and
the optional-arg-supplied variable will be NIL.

An optional parameter can be specified simply, like this:

  &optional optional-arg

in which case its default value is NIL, and you have no variable that
tells you whether the argument was supplied. Or you can specify just
the default value:

 &optional (optional-arg 42)

which indicates you are not interested in knowing whether the argument
was supplied---i.e. you don't care whether the caller actually
specified 42, or whether that value came in by way of default.

You also might want to take a look into keyword parameters, which are
Lisp's flexible way of passing a variable number of parameters which
are named by keywords. These are like optional arguments, but their
positional order doesn't matter because the caller specifies them by
name in any order. Inside the function body, they work a lot like
optional parameters, in that they are bound to variable names, have
default values if they are omitted, and there is a way to tell whether
a keyword parameter was specified or not.

A function can capture the list keyword paramters using &rest also, and
that list is a de facto property list.
From: Pascal Bourguignon
Subject: Re: &rest args
Date: 
Message-ID: <87u0nwnyfl.fsf@thalassa.informatimago.com>
"Asuka" <········@hotmail.com> writes:

> Hi, I've got a function with n arguments. The point is that I need the name 
> of each argument, how can I get it if its possible?

The names of the arguments are in the source: you have them under your nose!

    (defun f (arg1 arg2 arg3 ... argn)
        (format t "name of first argument is ~A" "arg1")
        ;; ...
        (format t "name of nth argument is ~A" "argn"))


Or:

If the function is not yours and you don't have the source, then you
may have the luck of being using an implementation that keeps
sufficient information about the function. eg, in clisp:

(second (function-lambda-expression
                 'com.informatimago.pjb:list-all-symbols))
--> (PACKAGE &KEY (COM.INFORMATIMAGO.PJB::SORTED T))

So the name of the arguments are PACKAGE and COM.INFORMATIMAGO.PJB::SORTED
but most implementations return NIL for function-lambda-expression

Even clisp returns NIL for primitive functions:

[5]> (function-lambda-expression 'sin)
NIL ;
NIL ;
SIN


Note that some functions are generic, and then the name of the
arguments declared in the defgeneric may be irrelevant, and each
argument may have a different name in a different method.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Grace personified,
I leap into the window.
I meant to do that.
From: Ulrich Hobelmann
Subject: Re: &rest args
Date: 
Message-ID: <38idokF5p6ii9U1@individual.net>
Asuka wrote:
> Hi, I've got a function with n arguments. The point is that I need the name 
> of each argument, how can I get it if its possible?
> 

You are not really clear in your question.

If you want a function that takes one list as a named argument, do that:
(defun foo (list)
   ...)

If you want a function that takes an arbitrary number of arguments, 
&rest should work (and will also bind the parameters to list, as above):
(defun foo (&rest list)
   ...)

If you want exactly n arguments, write n of them:
(defun foo (a1 a2 ... an)
   ...)

If you want an arbitrary number of arguments that are keyed, like in the 
call (foo :bla 1 :x 3) you can use one of the first two methods and use 
association-list functions to get the respective parameter.
From: Tony
Subject: Re: &rest args
Date: 
Message-ID: <d00m4c$e3f$1@nnrp.waia.asn.au>
It's probably a bit presumptuous of me to reply as I am still learning Lisp,
but I'd like to help if I can.

I'm guessing that Asuka might wish to examine the actual symbolic names
passed to the function as arguments?  If so, then I believe this can only be
done through a macro.

For example:
(defmacro see-names (&rest rest)

`(dolist (ele ',rest)

(format t "~A~%" ele)))

Should display the names of any variables passed to see-names.

Hope this helps.


"Asuka" <········@hotmail.com> wrote in message
·················@nsnmpen3-gest.nuria.telefonica-data.net...
> Hi, I've got a function with n arguments. The point is that I need the
name
> of each argument, how can I get it if its possible?
>
>
> Thanx
>
>
From: Peter Lewerin
Subject: Re: &rest args
Date: 
Message-ID: <b72f3640.0503010634.41cb536@posting.google.com>
"Tony" <··········@email.com> wrote

> For example:
> (defmacro see-names (&rest rest)
> 
> `(dolist (ele ',rest)
> 
> (format t "~A~%" ele)))

Or even:

  (defmacro see-names (&rest rest)
    `(format t "~{~S~%~}" ',rest))

As Pascal noted, what this macro prints is the formal arguments to the call.
From: Pascal Bourguignon
Subject: Re: &rest args
Date: 
Message-ID: <87hdjvobx2.fsf@thalassa.informatimago.com>
"Tony" <··········@email.com> writes:
> "Asuka" <········@hotmail.com> wrote in message
> ·················@nsnmpen3-gest.nuria.telefonica-data.net...
> > Hi, I've got a function with n arguments. The point is that I need the
> > name
> > of each argument, how can I get it if its possible?
>
> It's probably a bit presumptuous of me to reply as I am still learning Lisp,
> but I'd like to help if I can.
> 
> I'm guessing that Asuka might wish to examine the actual symbolic names
> passed to the function as arguments?  If so, then I believe this can only be
> done through a macro.
> 
> For example:
> (defmacro see-names (&rest rest)
> 
> `(dolist (ele ',rest)
> 
> (format t "~A~%" ele)))
> 
> Should display the names of any variables passed to see-names.
> 
> Hope this helps.
 

It may be what Asuka's asking, but what's the name of (1+ x) or (sin 3) ?

[23]> (see-names (1+ x) (sin 3) a)
(1+ X)
(SIN 3)
A
--> NIL


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Kitty like plastic.
Confuses for litter box.
Don't leave tarp around.