* Assign a function to a variable, and invoke it
@ 2007-07-30 22:22 troelskn
2007-07-30 22:52 ` troelskn
2007-07-30 22:56 ` Drew Adams
0 siblings, 2 replies; 4+ messages in thread
From: troelskn @ 2007-07-30 22:22 UTC (permalink / raw)
To: help-gnu-emacs
I'm trying to assign an existing function to a variable, so I can call
that variable, rather than the actual function directly. The aim is to
have a single point, where I can change behaviour for my module. The
code I have so far is:
(defvar my-browse-url 'browse-url)
...
(my-browse-url "http://example.com")
I suppose that functions and variables have different namespaces in
elisp? How do I invoke the function, which my-browse-url points to?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Assign a function to a variable, and invoke it
2007-07-30 22:22 Assign a function to a variable, and invoke it troelskn
@ 2007-07-30 22:52 ` troelskn
2007-07-30 22:56 ` Joost Kremers
2007-07-30 22:56 ` Drew Adams
1 sibling, 1 reply; 4+ messages in thread
From: troelskn @ 2007-07-30 22:52 UTC (permalink / raw)
To: help-gnu-emacs
On Jul 31, 12:22 am, troelskn <troel...@gmail.com> wrote:
> I'm trying to assign an existing function to a variable, so I can call
> that variable, rather than the actual function directly. The aim is to
> have a single point, where I can change behaviour for my module. The
> code I have so far is:
>
> (defvar my-browse-url 'browse-url)
> ...
> (my-browse-url "http://example.com")
>
> I suppose that functions and variables have different namespaces in
> elisp? How do I invoke the function, which my-browse-url points to?
I figured it out. I need to use funcall
http://www.delorie.com/gnu/docs/elisp-manual-21/elisp_168.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Assign a function to a variable, and invoke it
2007-07-30 22:52 ` troelskn
@ 2007-07-30 22:56 ` Joost Kremers
0 siblings, 0 replies; 4+ messages in thread
From: Joost Kremers @ 2007-07-30 22:56 UTC (permalink / raw)
To: help-gnu-emacs
troelskn wrote:
> On Jul 31, 12:22 am, troelskn <troel...@gmail.com> wrote:
>> I'm trying to assign an existing function to a variable, so I can call
>> that variable, rather than the actual function directly. The aim is to
>> have a single point, where I can change behaviour for my module. The
>> code I have so far is:
>>
>> (defvar my-browse-url 'browse-url)
>> ...
>> (my-browse-url "http://example.com")
>>
>> I suppose that functions and variables have different namespaces in
>> elisp?
yup.
> How do I invoke the function, which my-browse-url points to?
>
> I figured it out. I need to use funcall
or perhaps use fset or defalias?
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Assign a function to a variable, and invoke it
2007-07-30 22:22 Assign a function to a variable, and invoke it troelskn
2007-07-30 22:52 ` troelskn
@ 2007-07-30 22:56 ` Drew Adams
1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2007-07-30 22:56 UTC (permalink / raw)
To: troelskn, help-gnu-emacs
> (defvar my-browse-url 'browse-url)
> ...
> (my-browse-url "http://example.com")
>
> I suppose that functions and variables have different namespaces in
> elisp? How do I invoke the function, which my-browse-url points to?
Invoke the function using `funcall' or `apply': (funcall my-browse-url).
A symbol, such as `my-browse-url' or `browse-url', has a value cell and a
function cell, so the same symbol can act as a function (via its function
cell) and as a variable (via its value cell).
When evaluated, the symbol's value is returned (from its value cell). In a
function call, as in (browse-url), its function cell is used. When you do
(funcall my-browse-url), the symbol `my-browse-url' is evaluated (value
cell) to the symbol `browse-url', and then the function in the function cell
of that symbol, `browse-url', is called (by `funcall').
See the Elisp manual in Emacs (C-h i) for a better and more complete
explanation of all of this - it is your friend.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-07-30 22:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-30 22:22 Assign a function to a variable, and invoke it troelskn
2007-07-30 22:52 ` troelskn
2007-07-30 22:56 ` Joost Kremers
2007-07-30 22:56 ` 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).