unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "troelskn" <troelskn@gmail.com>, <help-gnu-emacs@gnu.org>
Subject: RE: Assign a function to a variable, and invoke it
Date: Mon, 30 Jul 2007 15:56:16 -0700	[thread overview]
Message-ID: <DNEMKBNJBGPAOPIJOOICGEGMDOAA.drew.adams@oracle.com> (raw)
In-Reply-To: <1185834175.653370.242000@22g2000hsm.googlegroups.com>

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

      parent reply	other threads:[~2007-07-30 22:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DNEMKBNJBGPAOPIJOOICGEGMDOAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=troelskn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).