[Top][All Lists]

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

Re: eval trouble

From: David Kastrup
Subject: Re: eval trouble
Date: Mon, 25 Aug 2008 21:48:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

"Lennart Borgman (gmail)" <address@hidden> writes:

> Lennart Borgman (gmail) wrote:
>> I expected the code below to give me a function named
>> mumamo-repl4-my-own9-mode. It does not.

It does.  It gives you a function named mumamo-repl4-my-own9-mode.  It
just does not make the name known to the world.

A symbol has four cells: a function cell, a name, a value cell and a
property list.  And you can intern a symbol into an OBARRAY, which is
sort of a hash references by name.

The Lisp reader identifies names with symbols by looking them up in the
global 'obarray.

IIRC, there are no functions to change a symbol's name (which is fixed
at creation time), and there is no way to enter a symbol into an obarray
at any index except its fixed name.  And you can only enter symbols into
a single obarray at most, at creation time when you specify the symbol's
name to "intern".  If you don't want to enter it into any obarray, use
make-symbol.  The given symbol has a name, but you can't reference it by
its name then.

>> Can someone please explain what I am doing wrong?
>> Interestingly if I do describe-variable on xx and then use the shown value t
>>   (setq xx THE-SHOWN-VALUE
>> then
>>    (eval xx)
>> does what I want.

Sure, because you then store the symbol itself and don't need its name
as a reference.

>> Here is the code that does NOT work:
>> (defun mumamo-define-no-mode (mode-sym)
>>   (let ((mumamo-repl4 (make-symbol (format "mumamo-repl4-%s" mode-sym)))
> It works if I replace make-symbol with intern. But why does eval care
> about that?

Because eval, when given the string "'mumamo-repl4-mode" will look up
mumamo-repl4-mode in the global obarray, and there is nothing with that
name in that obarray.

A symbol with that name exists, but not referenced through its name.

Each call of make-symbol creates a new symbol, like each call of list
creates a new list.

(eq (make-symbol "x") (make-symbol "x")) -> nil
(eq (intern "x") 'x) -> t
(make-symbol "x") -> x

Note that the last line just prints the _name_ of the created symbol.
It does not mean that you can use the name to get back the symbol, just

(eq 1.0 1.0) -> nil

creates two different objects which are not EQ.

David Kastrup, Kriemhildstr. 15, 44793 Bochum

reply via email to

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