* symbols and cells
@ 2014-05-15 17:10 Christopher Howard
2014-05-15 20:16 ` Michael Heerdegen
0 siblings, 1 reply; 3+ messages in thread
From: Christopher Howard @ 2014-05-15 17:10 UTC (permalink / raw)
To: Gnu Emacs Help
I'm still working through the earlier parts of the Elisp
documentation, but I am curious: How does one define the variable cell
and function cell for an /uninterned/ symbol? The docs indicate you
can do this:
(defvar sym (make-symbol "foo"))
But how do you add a function or variable value to foo without
interning it?
On a related note, I'm curious about this perverse construction:
(defvar sym1 (lambda (n) (+ 1 n)))
Is it actually possible to call the the lambda somehow?
ELISP> sym1
(lambda
(n)
(+ 1 n))
ELISP> (sym1)
*** Eval error *** Symbol's function definition is void: sym1
ELISP> (eval sym1)
(lambda
(n)
(+ 1 n))
ELISP> ((eval sym1))
*** Eval error *** Invalid function: (eval sym1)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: symbols and cells
2014-05-15 17:10 symbols and cells Christopher Howard
@ 2014-05-15 20:16 ` Michael Heerdegen
0 siblings, 0 replies; 3+ messages in thread
From: Michael Heerdegen @ 2014-05-15 20:16 UTC (permalink / raw)
To: help-gnu-emacs
Christopher Howard <cmhoward2@alaska.edu> writes:
> I'm still working through the earlier parts of the Elisp
> documentation, but I am curious: How does one define the variable cell
> and function cell for an /uninterned/ symbol? The docs indicate you
> can do this:
>
> (defvar sym (make-symbol "foo"))
>
> But how do you add a function or variable value to foo without
> interning it?
"Interning it" is a bit imprecise, since an uninterned symbol can't be
interned, only the string "foo" could be interned, and the result would be
different from any uninterned symbol of the same name.
You can use the functions `set' to set the value cell and `fset' to set
the function cell.
An even better question is: how would you call this uninterned symbol as a
function...?
Using uninterned symbols is almost only useful when macros are involved.
You should not care too much about them until you use macros.
> On a related note, I'm curious about this perverse construction:
>
> (defvar sym1 (lambda (n) (+ 1 n)))
>
> Is it actually possible to call the the lambda somehow?
Of course - with `funcall'. And it's not perverse at all in Lisp where
functions are first class objects.
That Elisp is Lisp 2 (symbols have separate value and function cells)
doesn't mean that you can't bind a variable to a function (i.e., set the
value cell of a symbol to a function). On the contrary, this is quite
normal.
Michael.
^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <mailman.1410.1400173825.1147.help-gnu-emacs@gnu.org>]
* Re: symbols and cells
[not found] <mailman.1410.1400173825.1147.help-gnu-emacs@gnu.org>
@ 2014-05-15 18:07 ` Pascal J. Bourguignon
0 siblings, 0 replies; 3+ messages in thread
From: Pascal J. Bourguignon @ 2014-05-15 18:07 UTC (permalink / raw)
To: help-gnu-emacs
Christopher Howard <cmhoward2@alaska.edu> writes:
> I'm still working through the earlier parts of the Elisp
> documentation, but I am curious: How does one define the variable cell
> and function cell for an /uninterned/ symbol? The docs indicate you
> can do this:
>
> (defvar sym (make-symbol "foo"))
>
> But how do you add a function or variable value to foo without
> interning it?
(require 'cl)
(setf (symbol-value sym) 42
(symbol-function sym) (lambda () 33))
(eval sym) --> 42
(eval (list sym)) --> 33
> On a related note, I'm curious about this perverse construction:
>
> (defvar sym1 (lambda (n) (+ 1 n)))
>
> Is it actually possible to call the the lambda somehow?
(funcall sym1 (symbol-value sym)) --> 43
--
__Pascal Bourguignon__
http://www.informatimago.com/
"Le mercure monte ? C'est le moment d'acheter !"
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-05-15 20:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-15 17:10 symbols and cells Christopher Howard
2014-05-15 20:16 ` Michael Heerdegen
[not found] <mailman.1410.1400173825.1147.help-gnu-emacs@gnu.org>
2014-05-15 18:07 ` Pascal J. Bourguignon
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.