all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* funcallable-p?
@ 2007-08-26  0:40 Drew Adams
  0 siblings, 0 replies; 17+ messages in thread
From: Drew Adams @ 2007-08-26  0:40 UTC (permalink / raw)
  To: Help-Gnu-Emacs

What's a good way to test the first argument to `funcall' or `apply', to
ensure that it is appropriate?

`functionp' won't do it, because it allows special forms and macros. I can
imagine doing a case analyis on the function-cell value, but what's a
concise and elegant idiom for this test? I don't see one used in the Lisp
source files; I guess each occurrence there more or less knows what argument
to expect.

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

* Re: funcallable-p?
       [not found] <mailman.5334.1188088931.32220.help-gnu-emacs@gnu.org>
@ 2007-08-26  5:07 ` Stefan Monnier
  2007-08-26  6:01   ` funcallable-p? Drew Adams
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2007-08-26  5:07 UTC (permalink / raw)
  To: help-gnu-emacs

> What's a good way to test the first argument to `funcall' or `apply', to
> ensure that it is appropriate?

`functionp'

> `functionp' won't do it, because it allows special forms and macros.

If it does it's a bug: please report it with a precise test case.


        Stefan

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

* RE: funcallable-p?
  2007-08-26  5:07 ` funcallable-p? Stefan Monnier
@ 2007-08-26  6:01   ` Drew Adams
  2007-08-27  4:05     ` funcallable-p? Stefan Monnier
  0 siblings, 1 reply; 17+ messages in thread
From: Drew Adams @ 2007-08-26  6:01 UTC (permalink / raw)
  To: Stefan Monnier, help-gnu-emacs

> > What's a good way to test the first argument to `funcall' or `apply', to
> > ensure that it is appropriate?
>
> `functionp'
>
> > `functionp' won't do it, because it allows special forms and macros.
>
> If it does it's a bug: please report it with a precise test case.

That's the impression I got from 1) the doc and 2) (functionp 'and) -> t,
(funcall 'and t) -> Invalid function: and.

Elisp manual: "This function returns `t' if OBJECT is any kind of function,
or a special form, or, recursively, a symbol whose function definition is a
function or special form.  (This does not include macros.)"

I mispoke about macros. I really meant special forms. `functionp' doesn't
distinguish between functions and special forms, right? If so, is there an
idiom or convention for such a test, of shall I just test `functionp' and
not a member of the list of special forms?

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

* Re: funcallable-p?
       [not found] <mailman.5340.1188108088.32220.help-gnu-emacs@gnu.org>
@ 2007-08-26 10:53 ` Daniel Jensen
  2007-08-26 13:08   ` funcallable-p? Pascal Bourguignon
  2007-08-26 14:43   ` funcallable-p? Drew Adams
  2007-08-26 22:44 ` funcallable-p? Johan Bockgård
  1 sibling, 2 replies; 17+ messages in thread
From: Daniel Jensen @ 2007-08-26 10:53 UTC (permalink / raw)
  To: help-gnu-emacs

"Drew Adams" <drew.adams@oracle.com> writes:

> I mispoke about macros. I really meant special forms. `functionp' doesn't
> distinguish between functions and special forms, right? If so, is there an
> idiom or convention for such a test, of shall I just test `functionp' and
> not a member of the list of special forms?

You can use `subr-arity' to test for a special form.

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

* Re: funcallable-p?
  2007-08-26 10:53 ` funcallable-p? Daniel Jensen
@ 2007-08-26 13:08   ` Pascal Bourguignon
  2007-08-26 14:32     ` funcallable-p? Daniel Jensen
  2007-08-26 14:43   ` funcallable-p? Drew Adams
  1 sibling, 1 reply; 17+ messages in thread
From: Pascal Bourguignon @ 2007-08-26 13:08 UTC (permalink / raw)
  To: help-gnu-emacs

daniel@bigwalter.net (Daniel Jensen) writes:

> "Drew Adams" <drew.adams@oracle.com> writes:
>
>> I mispoke about macros. I really meant special forms. `functionp' doesn't
>> distinguish between functions and special forms, right? If so, is there an
>> idiom or convention for such a test, of shall I just test `functionp' and
>> not a member of the list of special forms?
>
> You can use `subr-arity' to test for a special form.

(subrp (symbol-function 'sin)) --> t

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

This is a signature virus.  Add me to your signature and help me to live.

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

* Re: funcallable-p?
  2007-08-26 13:08   ` funcallable-p? Pascal Bourguignon
@ 2007-08-26 14:32     ` Daniel Jensen
  2007-08-27 10:16       ` funcallable-p? Pascal Bourguignon
  0 siblings, 1 reply; 17+ messages in thread
From: Daniel Jensen @ 2007-08-26 14:32 UTC (permalink / raw)
  To: help-gnu-emacs

Pascal Bourguignon <pjb@informatimago.com> writes:

> daniel@bigwalter.net (Daniel Jensen) writes:
>
>> You can use `subr-arity' to test for a special form.
>
> (subrp (symbol-function 'sin)) --> t

What are you trying to say here?

(subr-arity (symbol-function 'sin))
=> (1 . 1)

(subr-arity (symbol-function 'and))
=> (0 . unevalled)

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

* RE: funcallable-p?
  2007-08-26 10:53 ` funcallable-p? Daniel Jensen
  2007-08-26 13:08   ` funcallable-p? Pascal Bourguignon
@ 2007-08-26 14:43   ` Drew Adams
  1 sibling, 0 replies; 17+ messages in thread
From: Drew Adams @ 2007-08-26 14:43 UTC (permalink / raw)
  To: Daniel Jensen, help-gnu-emacs

> > `functionp' doesn't distinguish between functions and
> > special forms, right? If so, is there an
> > idiom or convention for such a test, of shall I just test
> > `functionp' and not a member of the list of special forms?
>
> You can use `subr-arity' to test for a special form.

Thank you. That's a lot better than testing membership in a list that is
bound to get out of date. Unfortunately, it isn't available for Emacs 20,
but that's OK.

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

* Re: funcallable-p?
       [not found] <mailman.5340.1188108088.32220.help-gnu-emacs@gnu.org>
  2007-08-26 10:53 ` funcallable-p? Daniel Jensen
@ 2007-08-26 22:44 ` Johan Bockgård
  2007-08-27  0:03   ` funcallable-p? Drew Adams
                     ` (2 more replies)
  1 sibling, 3 replies; 17+ messages in thread
From: Johan Bockgård @ 2007-08-26 22:44 UTC (permalink / raw)
  To: help-gnu-emacs

"Drew Adams" <drew.adams@oracle.com> writes:

> I mispoke about macros. I really meant special forms. `functionp'
> doesn't distinguish between functions and special forms, right?

FWIW, it used to include macros before Emacs 22. (I wonder why the
current meaning was chosen.)

-- 
Johan Bockgård

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

* RE: funcallable-p?
  2007-08-26 22:44 ` funcallable-p? Johan Bockgård
@ 2007-08-27  0:03   ` Drew Adams
  2007-08-27  3:20   ` funcallable-p? Eli Zaretskii
       [not found]   ` <mailman.5381.1188184866.32220.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 17+ messages in thread
From: Drew Adams @ 2007-08-27  0:03 UTC (permalink / raw)
  To: Johan "Bockgård", help-gnu-emacs

> > I mispoke about macros. I really meant special forms. `functionp'
> > doesn't distinguish between functions and special forms, right?
> 
> FWIW, it used to include macros before Emacs 22. (I wonder why the
> current meaning was chosen.)

Thanks for pointing that out. I tend to work much of the time in Emacs 20, so it's possible I first read the doc there, and then read it again in Emacs 22 after Stefan's reply. (I too wonder about the choice.)

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

* Re: funcallable-p?
  2007-08-26 22:44 ` funcallable-p? Johan Bockgård
  2007-08-27  0:03   ` funcallable-p? Drew Adams
@ 2007-08-27  3:20   ` Eli Zaretskii
       [not found]   ` <mailman.5381.1188184866.32220.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 17+ messages in thread
From: Eli Zaretskii @ 2007-08-27  3:20 UTC (permalink / raw)
  To: help-gnu-emacs

> From: bojohan+news@dd.chalmers.se (Johan =?utf-8?Q?Bockg=C3=A5rd?=)
> Date: Mon, 27 Aug 2007 00:44:00 +0200
> 
> "Drew Adams" <drew.adams@oracle.com> writes:
> 
> > I mispoke about macros. I really meant special forms. `functionp'
> > doesn't distinguish between functions and special forms, right?
> 
> FWIW, it used to include macros before Emacs 22. (I wonder why the
> current meaning was chosen.)

I recall that there was a long discussion about this on the developers
list when this change was made, you may wish to look it up.

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

* Re: funcallable-p?
  2007-08-26  6:01   ` funcallable-p? Drew Adams
@ 2007-08-27  4:05     ` Stefan Monnier
  2007-08-27  5:11       ` funcallable-p? Drew Adams
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2007-08-27  4:05 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

>> > What's a good way to test the first argument to `funcall' or `apply', to
>> > ensure that it is appropriate?
>> 
>> `functionp'
>> 
>> > `functionp' won't do it, because it allows special forms and macros.
>> 
>> If it does it's a bug: please report it with a precise test case.

> That's the impression I got from 1) the doc and 2) (functionp 'and) -> t,
> (funcall 'and t) -> Invalid function: and.

> Elisp manual: "This function returns `t' if OBJECT is any kind of function,
> or a special form, or, recursively, a symbol whose function definition is a
> function or special form.  (This does not include macros.)"

Indeed you're right.  I think it's an error in functionp.
Please report it via M-x report-emacs-bug.


        Stefan

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

* RE: funcallable-p?
  2007-08-27  4:05     ` funcallable-p? Stefan Monnier
@ 2007-08-27  5:11       ` Drew Adams
  2007-08-27 13:55         ` funcallable-p? Stefan Monnier
  0 siblings, 1 reply; 17+ messages in thread
From: Drew Adams @ 2007-08-27  5:11 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

> >> > What's a good way to test the first argument to `funcall' or
> >> > `apply', to ensure that it is appropriate?
> >>
> >> `functionp'
> >>
> >> > `functionp' won't do it, because it allows special forms and macros.
> >>
> >> If it does it's a bug: please report it with a precise test case.
>
> > That's the impression I got from 1) the doc and 2) (functionp
> > 'and) -> t, (funcall 'and t) -> Invalid function: and.
>
> > Elisp manual: "This function returns `t' if OBJECT is any kind
> > of function, or a special form, or, recursively, a symbol whose
> > function definition is a function or special form.  (This does
> > not include macros.)"
>
> Indeed you're right.  I think it's an error in functionp.
> Please report it via M-x report-emacs-bug.

I'm not sure what the error is. That is, I don't know what the intended
design is or why. The behavior seems to correspond correctly to the doc, so
I don't know what the bug would be.

If you understand this (I do not) and, as you say, you think it is an error,
then you should perhaps report it as a bug.

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

* Re: funcallable-p?
  2007-08-26 14:32     ` funcallable-p? Daniel Jensen
@ 2007-08-27 10:16       ` Pascal Bourguignon
  0 siblings, 0 replies; 17+ messages in thread
From: Pascal Bourguignon @ 2007-08-27 10:16 UTC (permalink / raw)
  To: help-gnu-emacs

daniel@bigwalter.net (Daniel Jensen) writes:

> Pascal Bourguignon <pjb@informatimago.com> writes:
>
>> daniel@bigwalter.net (Daniel Jensen) writes:
>>
>>> You can use `subr-arity' to test for a special form.
>>
>> (subrp (symbol-function 'sin)) --> t
>
> What are you trying to say here?
>
> (subr-arity (symbol-function 'sin))
> => (1 . 1)
>
> (subr-arity (symbol-function 'and))
> => (0 . unevalled)

Sorry, I didn't know subr-arity, and I "read" that we could test for a
subr.


subr-arity sounds nice.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Litter box not here.
You must have moved it again.
I'll poop in the sink. 

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

* Re: funcallable-p?
  2007-08-27  5:11       ` funcallable-p? Drew Adams
@ 2007-08-27 13:55         ` Stefan Monnier
  2007-08-27 14:41           ` funcallable-p? Drew Adams
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2007-08-27 13:55 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

>> Indeed you're right.  I think it's an error in functionp.
>> Please report it via M-x report-emacs-bug.

> I'm not sure what the error is. That is, I don't know what the intended
> design is or why. The behavior seems to correspond correctly to the doc, so
> I don't know what the bug would be.

The error is that functionp does not provide what you want.


        Stefan

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

* RE: funcallable-p?
  2007-08-27 13:55         ` funcallable-p? Stefan Monnier
@ 2007-08-27 14:41           ` Drew Adams
  2007-08-27 20:08             ` funcallable-p? Stefan Monnier
  0 siblings, 1 reply; 17+ messages in thread
From: Drew Adams @ 2007-08-27 14:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

> >> Indeed you're right.  I think it's an error in functionp.
> >> Please report it via M-x report-emacs-bug.
>
> > I'm not sure what the error is. That is, I don't know what the intended
> > design is or why. The behavior seems to correspond correctly to
> > the doc, so I don't know what the bug would be.
>
> The error is that functionp does not provide what you want.

I see. I can file a bug saying that it does not provide what I want, but was
it supposed to? I don't know what the intention was. Going by the doc, the
implementation seems correct.

So, should fboundp be fixed to be, in effect, funcallable, or should a new
function, `funcallablep' (or whatever) created for that?

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

* Re: funcallable-p?
       [not found]   ` <mailman.5381.1188184866.32220.help-gnu-emacs@gnu.org>
@ 2007-08-27 18:04     ` Johan Bockgård
  0 siblings, 0 replies; 17+ messages in thread
From: Johan Bockgård @ 2007-08-27 18:04 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: bojohan+news@dd.chalmers.se (Johan =?utf-8?Q?Bockg=C3=A5rd?=)
>> Date: Mon, 27 Aug 2007 00:44:00 +0200
>> 
>> FWIW, [functionp] used to include macros before Emacs 22. (I wonder
>> why the current meaning was chosen.)
>
> I recall that there was a long discussion about this on the developers
> list when this change was made, you may wish to look it up.

I've tried to look it up before, and I tried again but failed. I can't
find any relevant mentions of "functionp" on emacs-devel around November
2001.

The change was

    2001-11-09  Miles Bader

            * subr.el (functionp): Don't consider macros as functions.

-- 
Johan Bockgård

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

* Re: funcallable-p?
  2007-08-27 14:41           ` funcallable-p? Drew Adams
@ 2007-08-27 20:08             ` Stefan Monnier
  0 siblings, 0 replies; 17+ messages in thread
From: Stefan Monnier @ 2007-08-27 20:08 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

>> >> Indeed you're right.  I think it's an error in functionp.
>> >> Please report it via M-x report-emacs-bug.
>> 
>> > I'm not sure what the error is. That is, I don't know what the intended
>> > design is or why. The behavior seems to correspond correctly to
>> > the doc, so I don't know what the bug would be.
>> 
>> The error is that functionp does not provide what you want.

> I see. I can file a bug saying that it does not provide what I want, but was
> it supposed to?

I don't know.  Just file the report and we can discuss it then.


        Stefan

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

end of thread, other threads:[~2007-08-27 20:08 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-26  0:40 funcallable-p? Drew Adams
     [not found] <mailman.5334.1188088931.32220.help-gnu-emacs@gnu.org>
2007-08-26  5:07 ` funcallable-p? Stefan Monnier
2007-08-26  6:01   ` funcallable-p? Drew Adams
2007-08-27  4:05     ` funcallable-p? Stefan Monnier
2007-08-27  5:11       ` funcallable-p? Drew Adams
2007-08-27 13:55         ` funcallable-p? Stefan Monnier
2007-08-27 14:41           ` funcallable-p? Drew Adams
2007-08-27 20:08             ` funcallable-p? Stefan Monnier
     [not found] <mailman.5340.1188108088.32220.help-gnu-emacs@gnu.org>
2007-08-26 10:53 ` funcallable-p? Daniel Jensen
2007-08-26 13:08   ` funcallable-p? Pascal Bourguignon
2007-08-26 14:32     ` funcallable-p? Daniel Jensen
2007-08-27 10:16       ` funcallable-p? Pascal Bourguignon
2007-08-26 14:43   ` funcallable-p? Drew Adams
2007-08-26 22:44 ` funcallable-p? Johan Bockgård
2007-08-27  0:03   ` funcallable-p? Drew Adams
2007-08-27  3:20   ` funcallable-p? Eli Zaretskii
     [not found]   ` <mailman.5381.1188184866.32220.help-gnu-emacs@gnu.org>
2007-08-27 18:04     ` funcallable-p? Johan Bockgård

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.