unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Refer to List of Arguments in Emacs Lisp Function
@ 2014-11-13  8:02 Alexander Shukaev
  2014-11-13 16:16 ` Marcin Borkowski
       [not found] ` <mailman.13556.1415895434.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Alexander Shukaev @ 2014-11-13  8:02 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I can't find whether there is a possibility to refer to the whole list of
arguments of a function in Emacs Lisp. For example:

(defun move (x y z)
  (apply do-move (args))

What I mean by (args) primitive here is a list (x y z). This use case
illustrates usefulness of such a primitive, i.e. forwarding of arguments to
another internal call without a need to rewrite them by hand. (length
(args)) might be useful in some cases too. Is there anything like that in
Emacs Lisp already?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
       [not found] <mailman.13526.1415865742.1147.help-gnu-emacs@gnu.org>
@ 2014-11-13  8:27 ` Joost Kremers
  2014-11-13  8:35   ` Alexander Shukaev
  2014-11-13 16:02 ` Barry Margolin
  2014-11-17 11:04 ` Ted Zlatanov
  2 siblings, 1 reply; 12+ messages in thread
From: Joost Kremers @ 2014-11-13  8:27 UTC (permalink / raw)
  To: help-gnu-emacs

Alexander Shukaev wrote:
> (defun move (x y z)
>   (apply do-move (args))

(defun move (&rest args)
  (apply #'do-move args)))

HTH

-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
  2014-11-13  8:27 ` Refer to List of Arguments in Emacs Lisp Function Joost Kremers
@ 2014-11-13  8:35   ` Alexander Shukaev
  2014-11-13 16:58     ` Andreas Röhler
       [not found]     ` <mailman.13561.1415897958.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Alexander Shukaev @ 2014-11-13  8:35 UTC (permalink / raw)
  To: Joost Kremers; +Cc: help-gnu-emacs

>
> (defun move (&rest args)
>   (apply #'do-move args)))
>

I'm aware of that, but that's not what I'm looking for... I'm interested in
required arguments in the first place.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
       [not found] <mailman.13526.1415865742.1147.help-gnu-emacs@gnu.org>
  2014-11-13  8:27 ` Refer to List of Arguments in Emacs Lisp Function Joost Kremers
@ 2014-11-13 16:02 ` Barry Margolin
  2014-11-17 11:04 ` Ted Zlatanov
  2 siblings, 0 replies; 12+ messages in thread
From: Barry Margolin @ 2014-11-13 16:02 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.13526.1415865742.1147.help-gnu-emacs@gnu.org>,
 Alexander Shukaev <haroogan@gmail.com> wrote:

> Hello,
> 
> I can't find whether there is a possibility to refer to the whole list of
> arguments of a function in Emacs Lisp. For example:
> 
> (defun move (x y z)
>   (apply do-move (args))
> 
> What I mean by (args) primitive here is a list (x y z). This use case
> illustrates usefulness of such a primitive, i.e. forwarding of arguments to
> another internal call without a need to rewrite them by hand. (length
> (args)) might be useful in some cases too. Is there anything like that in
> Emacs Lisp already?

I don't think there's any built-in way to get a list of the arguments 
that were named separately in the argument list. Emacs Lisp's argument 
processing is very similar to Common Lisp's, and it doesn't have a way 
to do it, either. So you have to refer to the named arguments themselves:

(defun move (x y z)
  (apply do-move (list x y z)))

(defun move (x y z)
  (funcall do-move x y z))

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
  2014-11-13  8:02 Alexander Shukaev
@ 2014-11-13 16:16 ` Marcin Borkowski
       [not found] ` <mailman.13556.1415895434.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 12+ messages in thread
From: Marcin Borkowski @ 2014-11-13 16:16 UTC (permalink / raw)
  To: help-gnu-emacs


On 2014-11-13, at 09:02, Alexander Shukaev wrote:

> Hello,
>
> I can't find whether there is a possibility to refer to the whole list of
> arguments of a function in Emacs Lisp. For example:
>
> (defun move (x y z)
>   (apply do-move (args))
>
> What I mean by (args) primitive here is a list (x y z). This use case
> illustrates usefulness of such a primitive, i.e. forwarding of arguments to
> another internal call without a need to rewrite them by hand. (length
> (args)) might be useful in some cases too. Is there anything like that in
> Emacs Lisp already?

(defun move (&rest args)
  (apply #'do-move args))

Note that (apply do-move (args)) would not work: first, you have to
quote do-move, second, (args) would try to call a function `args'.

Hth,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
  2014-11-13  8:35   ` Alexander Shukaev
@ 2014-11-13 16:58     ` Andreas Röhler
  2014-11-14 13:35       ` Nicolas Richard
       [not found]     ` <mailman.13561.1415897958.1147.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 12+ messages in thread
From: Andreas Röhler @ 2014-11-13 16:58 UTC (permalink / raw)
  To: help-gnu-emacs

On 13.11.2014 09:35, Alexander Shukaev wrote:
>>
>> (defun move (&rest args)
>>    (apply #'do-move args)))
>>
>
> I'm aware of that, but that's not what I'm looking for... I'm interested in
> required arguments in the first place.
>

What about that way:

(cadr (symbol-function 'MY-FUNCTION))



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
       [not found]     ` <mailman.13561.1415897958.1147.help-gnu-emacs@gnu.org>
@ 2014-11-13 19:20       ` Barry Margolin
  2014-11-14  1:52         ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: Barry Margolin @ 2014-11-13 19:20 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 656 bytes --]

In article <mailman.13561.1415897958.1147.help-gnu-emacs@gnu.org>,
 Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:

> On 13.11.2014 09:35, Alexander Shukaev wrote:
> >>
> >> (defun move (&rest args)
> >>    (apply #'do-move args)))
> >>
> >
> > I'm aware of that, but that's not what I'm looking for... I'm interested in
> > required arguments in the first place.
> >
> 
> What about that way:
> 
> (cadr (symbol-function 'MY-FUNCTION))

That will return the names of the arguments, not the list of actual 
arguments in a call.

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
       [not found] ` <mailman.13556.1415895434.1147.help-gnu-emacs@gnu.org>
@ 2014-11-13 19:23   ` Barry Margolin
  0 siblings, 0 replies; 12+ messages in thread
From: Barry Margolin @ 2014-11-13 19:23 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.13556.1415895434.1147.help-gnu-emacs@gnu.org>,
 Marcin Borkowski <mbork@wmi.amu.edu.pl> wrote:

> On 2014-11-13, at 09:02, Alexander Shukaev wrote:
> 
> > Hello,
> >
> > I can't find whether there is a possibility to refer to the whole list of
> > arguments of a function in Emacs Lisp. For example:
> >
> > (defun move (x y z)
> >   (apply do-move (args))
> >
> > What I mean by (args) primitive here is a list (x y z). This use case
> > illustrates usefulness of such a primitive, i.e. forwarding of arguments to
> > another internal call without a need to rewrite them by hand. (length
> > (args)) might be useful in some cases too. Is there anything like that in
> > Emacs Lisp already?
> 
> (defun move (&rest args)
>   (apply #'do-move args))
> 
> Note that (apply do-move (args)) would not work: first, you have to
> quote do-move, second, (args) would try to call a function `args'.

You don't have to quote do-move if it's a variable, e.g. in a context 
like:

(let ((do-move (if something #'move1 #'move2)))
  (apply do-move (args)))

And I think he was actually asking if there's a function that returns 
all the arguments, which you would calls as (args).

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
  2014-11-13 19:20       ` Barry Margolin
@ 2014-11-14  1:52         ` Stefan Monnier
  2014-11-14  3:56           ` Alexander Shukaev
  0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2014-11-14  1:52 UTC (permalink / raw)
  To: help-gnu-emacs

> That will return the names of the arguments, not the list of actual 
       ^^^^
       may

It may also signal an error.


        Stefan




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
  2014-11-14  1:52         ` Stefan Monnier
@ 2014-11-14  3:56           ` Alexander Shukaev
  0 siblings, 0 replies; 12+ messages in thread
From: Alexander Shukaev @ 2014-11-14  3:56 UTC (permalink / raw)
  Cc: help-gnu-emacs

It seems to me that this feature is relatively easy to implement by
modifying the `defun' macro. Would anyone be interested to see this in
future release of Emacs?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
  2014-11-13 16:58     ` Andreas Röhler
@ 2014-11-14 13:35       ` Nicolas Richard
  0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Richard @ 2014-11-14 13:35 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: help-gnu-emacs

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
> What about that way:
>
> (cadr (symbol-function 'MY-FUNCTION))

I guess this will bomb in lexbind context, no ?

-- 
Nicolas Richard



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Refer to List of Arguments in Emacs Lisp Function
       [not found] <mailman.13526.1415865742.1147.help-gnu-emacs@gnu.org>
  2014-11-13  8:27 ` Refer to List of Arguments in Emacs Lisp Function Joost Kremers
  2014-11-13 16:02 ` Barry Margolin
@ 2014-11-17 11:04 ` Ted Zlatanov
  2 siblings, 0 replies; 12+ messages in thread
From: Ted Zlatanov @ 2014-11-17 11:04 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, 13 Nov 2014 09:02:14 +0100 Alexander Shukaev <haroogan@gmail.com> wrote: 

AS> I can't find whether there is a possibility to refer to the whole list of
AS> arguments of a function in Emacs Lisp. For example:

AS> (defun move (x y z)
AS>   (apply do-move (args))

AS> What I mean by (args) primitive here is a list (x y z). This use case
AS> illustrates usefulness of such a primitive, i.e. forwarding of arguments to
AS> another internal call without a need to rewrite them by hand.

I think `apply-partially' and function aliasing are more typical
solution for this use case in today's Emacs. Macros also help, depending
on the situation. Not to say your need is not valid, but it's definitely
not common.

AS> (length (args)) might be useful in some cases too. Is there anything
AS> like that in Emacs Lisp already?

Sorry... I'm not aware of such a thing.

Ted


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-11-17 11:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.13526.1415865742.1147.help-gnu-emacs@gnu.org>
2014-11-13  8:27 ` Refer to List of Arguments in Emacs Lisp Function Joost Kremers
2014-11-13  8:35   ` Alexander Shukaev
2014-11-13 16:58     ` Andreas Röhler
2014-11-14 13:35       ` Nicolas Richard
     [not found]     ` <mailman.13561.1415897958.1147.help-gnu-emacs@gnu.org>
2014-11-13 19:20       ` Barry Margolin
2014-11-14  1:52         ` Stefan Monnier
2014-11-14  3:56           ` Alexander Shukaev
2014-11-13 16:02 ` Barry Margolin
2014-11-17 11:04 ` Ted Zlatanov
2014-11-13  8:02 Alexander Shukaev
2014-11-13 16:16 ` Marcin Borkowski
     [not found] ` <mailman.13556.1415895434.1147.help-gnu-emacs@gnu.org>
2014-11-13 19:23   ` Barry Margolin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).