help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Assign a function to a variable, and invoke it


From: Drew Adams
Subject: RE: Assign a function to a variable, and invoke it
Date: Mon, 30 Jul 2007 15:56:16 -0700

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]