unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Function pointer
@ 2009-04-14  7:20 Decebal
  2009-04-14  8:02 ` Harald Hanche-Olsen
  0 siblings, 1 reply; 4+ messages in thread
From: Decebal @ 2009-04-14  7:20 UTC (permalink / raw)
  To: help-gnu-emacs

Is it possible to work with function pointers?
The following works:
    (a-function)
but this does not work:
    (setq function 'a-function)
    (function)
this gives wrong number of arguments.


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

* Re: Function pointer
  2009-04-14  7:20 Function pointer Decebal
@ 2009-04-14  8:02 ` Harald Hanche-Olsen
  2009-04-14  8:41   ` Decebal
  0 siblings, 1 reply; 4+ messages in thread
From: Harald Hanche-Olsen @ 2009-04-14  8:02 UTC (permalink / raw)
  To: help-gnu-emacs

+ Decebal <CLDWesterhof@gmail.com>:

> Is it possible to work with function pointers?

No. Pointers are a low level concept not supported by elisp.

> The following works:
>     (a-function)
> but this does not work:
>     (setq function 'a-function)
>     (function)
> this gives wrong number of arguments.

Ah. So you're not after pointers, just a means of passing functions
around. You should be aware, then, that symbols can have two values
associated with them: The regular value, which is obtained by just using
the symbol, and the function value, which is consulted if the symbol is
in the function place of a for. You have assigned the symbol a-function
to the symbol function above, but that symbol also has a function value,
which you inadvertently used in the last line.

The elisp manual explains this. Go to node Symbols, then sub-node Symbol
Components.

The very short answer to your question: Use funcall, as in
    (funcall function)

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell


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

* Re: Function pointer
  2009-04-14  8:02 ` Harald Hanche-Olsen
@ 2009-04-14  8:41   ` Decebal
  2009-04-14 14:37     ` Drew Adams
  0 siblings, 1 reply; 4+ messages in thread
From: Decebal @ 2009-04-14  8:41 UTC (permalink / raw)
  To: help-gnu-emacs

On 14 apr, 10:02, Harald Hanche-Olsen <han...@math.ntnu.no> wrote:
> + Decebal <CLDWester...@gmail.com>:
> > The following works:
> >     (a-function)
> > but this does not work:
> >     (setq function 'a-function)
> >     (function)
> > this gives wrong number of arguments.
>
> Ah. So you're not after pointers, just a means of passing functions
> around. You should be aware, then, that symbols can have two values
> associated with them: The regular value, which is obtained by just using
> the symbol, and the function value, which is consulted if the symbol is
> in the function place of a for. You have assigned the symbol a-function
> to the symbol function above, but that symbol also has a function value,
> which you inadvertently used in the last line.
>
> The elisp manual explains this. Go to node Symbols, then sub-node Symbol
> Components.
>
> The very short answer to your question: Use funcall, as in
>     (funcall function)

Works likes a charm. Now I have the tools to build the 'little'
functionality I wanted. Thanks.


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

* RE: Function pointer
  2009-04-14  8:41   ` Decebal
@ 2009-04-14 14:37     ` Drew Adams
  0 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2009-04-14 14:37 UTC (permalink / raw)
  To: 'Decebal', help-gnu-emacs

> > >     (function)
> > > this gives wrong number of arguments.
...
> > The very short answer to your question: Use funcall, as in
> >     (funcall function)
> 
> Works likes a charm. Now I have the tools to build the 'little'
> functionality I wanted. Thanks.

BTW, the reason the error message complained about the wrong number of args is
that `function' is an existing special form - `C-h f function':

,----
| function is a special form in `C source code'.
| 
| (function arg)
| 
| Like `quote', but preferred for objects which are functions.
| In byte compilation, `function' causes its argument to be compiled.
| `quote' cannot do that.
`----

"Function" (special form) `function' expects one argument, and you gave it zero
args.





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

end of thread, other threads:[~2009-04-14 14:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-14  7:20 Function pointer Decebal
2009-04-14  8:02 ` Harald Hanche-Olsen
2009-04-14  8:41   ` Decebal
2009-04-14 14:37     ` Drew Adams

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).