* eval trouble @ 2008-08-25 16:56 Lennart Borgman (gmail) 2008-08-25 17:08 ` Lennart Borgman (gmail) [not found] ` <mailman.17509.1219684131.18990.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 15+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-25 16:56 UTC (permalink / raw) To: help-gnu-emacs@gnu.org I expected the code below to give me a function named mumamo-repl4-my-own9-mode. It does not. 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. 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))) (lighter (format "No %s" mode-sym)) (doc (format "MuMaMo replacement for the mode %s which was not found." mode-sym))) (setq xx `(define-derived-mode ,mumamo-repl4 fundamental-mode ,lighter ,doc)) (message "xx=%s" (pp-to-string xx)) (eval xx) )) (mumamo-define-no-mode 'my-own9-mode) ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: eval trouble 2008-08-25 16:56 eval trouble Lennart Borgman (gmail) @ 2008-08-25 17:08 ` Lennart Borgman (gmail) [not found] ` <mailman.17509.1219684131.18990.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 15+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-25 17:08 UTC (permalink / raw) To: help-gnu-emacs@gnu.org Lennart Borgman (gmail) wrote: > I expected the code below to give me a function named > mumamo-repl4-my-own9-mode. It does not. 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. > > 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? > (lighter (format "No %s" mode-sym)) > (doc > (format > "MuMaMo replacement for the mode %s which was not found." > mode-sym))) > (setq xx > `(define-derived-mode ,mumamo-repl4 fundamental-mode ,lighter ,doc)) > (message "xx=%s" (pp-to-string xx)) > (eval xx) > )) > > (mumamo-define-no-mode 'my-own9-mode) > > > ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.17509.1219684131.18990.help-gnu-emacs@gnu.org>]
* Re: eval trouble [not found] ` <mailman.17509.1219684131.18990.help-gnu-emacs@gnu.org> @ 2008-08-25 17:43 ` Pascal J. Bourguignon 2008-08-25 17:45 ` Lennart Borgman (gmail) [not found] ` <mailman.17512.1219686348.18990.help-gnu-emacs@gnu.org> 2008-08-25 19:48 ` David Kastrup 1 sibling, 2 replies; 15+ messages in thread From: Pascal J. Bourguignon @ 2008-08-25 17:43 UTC (permalink / raw) To: help-gnu-emacs "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: >> 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? eval doesn't care, but how would you be able to refer again to the defined thing if you don't have its name in some dictionary? It's like putting your suitcase to the baggage checkroom, and losing the key right away. As soon as the checkroom realises there's no more any key to unlock your suitcase, it'll recover the space and throw it to the garbage. -- __Pascal Bourguignon__ http://www.informatimago.com/ THIS IS A 100% MATTER PRODUCT: In the unlikely event that this merchandise should contact antimatter in any form, a catastrophic explosion will result. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: eval trouble 2008-08-25 17:43 ` Pascal J. Bourguignon @ 2008-08-25 17:45 ` Lennart Borgman (gmail) 2008-08-25 18:47 ` Pascal J. Bourguignon [not found] ` <mailman.17512.1219686348.18990.help-gnu-emacs@gnu.org> 1 sibling, 1 reply; 15+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-25 17:45 UTC (permalink / raw) To: Pascal J. Bourguignon; +Cc: help-gnu-emacs Pascal J. Bourguignon wrote: > "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: >>> 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? > > eval doesn't care, but how would you be able to refer again to the > defined thing if you don't have its name in some dictionary? Thanks. I see. I thought eval interned the symbol, or perhaps rather created an interned symbol. In this case it does not do that. Or am I still misunderstanding something. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: eval trouble 2008-08-25 17:45 ` Lennart Borgman (gmail) @ 2008-08-25 18:47 ` Pascal J. Bourguignon 2008-08-25 18:34 ` Lennart Borgman (gmail) 0 siblings, 1 reply; 15+ messages in thread From: Pascal J. Bourguignon @ 2008-08-25 18:47 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: help-gnu-emacs Lennart Borgman (gmail) writes: > Pascal J. Bourguignon wrote: > > "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: > >>> 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? > > > > eval doesn't care, but how would you be able to refer again to the > > defined thing if you don't have its name in some dictionary? > > > Thanks. I see. I thought eval interned the symbol, or perhaps rather > created an interned symbol. In this case it does not do that. > > Or am I still misunderstanding something. Only intern interns symbols. intern is called automatically only by the lisp reader. It's when a s-expression is read that symbols it contains are interned. When you call eval, it's already done. -- __Pascal Bourguignon__ http://www.informatimago.com/ CAUTION: The mass of this product contains the energy equivalent of 85 million tons of TNT per net ounce of weight. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: eval trouble 2008-08-25 18:47 ` Pascal J. Bourguignon @ 2008-08-25 18:34 ` Lennart Borgman (gmail) 0 siblings, 0 replies; 15+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-25 18:34 UTC (permalink / raw) To: pjb; +Cc: help-gnu-emacs Pascal J. Bourguignon wrote: > Lennart Borgman (gmail) writes: >> Pascal J. Bourguignon wrote: >>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: >>>>> 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? >>> eval doesn't care, but how would you be able to refer again to the >>> defined thing if you don't have its name in some dictionary? >> >> Thanks. I see. I thought eval interned the symbol, or perhaps rather >> created an interned symbol. In this case it does not do that. >> >> Or am I still misunderstanding something. > > Only intern interns symbols. intern is called automatically only by > the lisp reader. It's when a s-expression is read that symbols it > contains are interned. When you call eval, it's already done. Yepp. I was still misunderstanding. Thanks, that was very clear. ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.17512.1219686348.18990.help-gnu-emacs@gnu.org>]
* Re: eval trouble [not found] ` <mailman.17512.1219686348.18990.help-gnu-emacs@gnu.org> @ 2008-08-25 19:50 ` David Kastrup 2008-08-25 20:59 ` Lennart Borgman (gmail) [not found] ` <mailman.17522.1219697977.18990.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 15+ messages in thread From: David Kastrup @ 2008-08-25 19:50 UTC (permalink / raw) To: help-gnu-emacs "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: > Pascal J. Bourguignon wrote: >> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: >>>> 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? >> >> eval doesn't care, but how would you be able to refer again to the >> defined thing if you don't have its name in some dictionary? > > > Thanks. I see. I thought eval interned the symbol, or perhaps rather > created an interned symbol. In this case it does not do that. Eval _does_ create an interned symbol. But it is not EQ to the unique uninterned symbol that make-symbol creates. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: eval trouble 2008-08-25 19:50 ` David Kastrup @ 2008-08-25 20:59 ` Lennart Borgman (gmail) [not found] ` <mailman.17522.1219697977.18990.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 15+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-25 20:59 UTC (permalink / raw) To: David Kastrup; +Cc: help-gnu-emacs David Kastrup wrote: > "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: > >> Pascal J. Bourguignon wrote: >>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: >>>>> 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? >>> eval doesn't care, but how would you be able to refer again to the >>> defined thing if you don't have its name in some dictionary? >> >> Thanks. I see. I thought eval interned the symbol, or perhaps rather >> created an interned symbol. In this case it does not do that. > > Eval _does_ create an interned symbol. But it is not EQ to the unique > uninterned symbol that make-symbol creates. > I am a bit confused, but I guess you mean if the symbol does not exist: (let ((sym (make-symbol "xýzw"))) (eval `(progn (setq ,sym 1) (put ',sym 'some 'value)))) (mapatoms (lambda (atom) (when (string= (symbol-name atom) "xyzw") (error "Found %s" atom)))) ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.17522.1219697977.18990.help-gnu-emacs@gnu.org>]
* Re: eval trouble [not found] ` <mailman.17522.1219697977.18990.help-gnu-emacs@gnu.org> @ 2008-08-25 21:36 ` David Kastrup 2008-08-25 21:43 ` Lennart Borgman (gmail) 2008-09-14 20:57 ` David Combs 1 sibling, 1 reply; 15+ messages in thread From: David Kastrup @ 2008-08-25 21:36 UTC (permalink / raw) To: help-gnu-emacs "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: > David Kastrup wrote: >> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: >> >>> Pascal J. Bourguignon wrote: >>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: >>>>>> 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? >>>> eval doesn't care, but how would you be able to refer again to the >>>> defined thing if you don't have its name in some dictionary? >>> >>> Thanks. I see. I thought eval interned the symbol, or perhaps rather >>> created an interned symbol. In this case it does not do that. >> >> Eval _does_ create an interned symbol. But it is not EQ to the >> unique uninterned symbol that make-symbol creates. > > I am a bit confused, but I guess you mean if the symbol does not exist: > > (let ((sym (make-symbol "xýzw"))) > (eval `(progn (setq ,sym 1) > (put ',sym 'some 'value)))) Ok, I actually talked nonsense right now: eval does _not_ create or intern symbols. It is the Lisp reader that creates/interns symbols when you feed an identifier to it. The Lisp reader will, when given the above, maybe-create/intern/lookup all of let, sym, make-symbol, eval, \` or something similar, progn, setq, \, or something similar, sym, put, some and value. And whatever else follows. > (mapatoms (lambda (atom) > (when (string= (symbol-name atom) > "xyzw") > (error "Found %s" atom)))) Well, you wrote xýzw rather than xyzw above. But even if you didn't, as long as nothing else interned 'xyzw in some manner, such a symbol would not get found. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: eval trouble 2008-08-25 21:36 ` David Kastrup @ 2008-08-25 21:43 ` Lennart Borgman (gmail) 0 siblings, 0 replies; 15+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-25 21:43 UTC (permalink / raw) To: David Kastrup; +Cc: help-gnu-emacs David Kastrup wrote: > Ok, I actually talked nonsense right now: eval does _not_ create or > intern symbols. It is the Lisp reader that creates/interns symbols when > you feed an identifier to it. The Lisp reader will, when given the > above, maybe-create/intern/lookup all of let, sym, make-symbol, eval, \` > or something similar, progn, setq, \, or something similar, sym, put, > some and value. And whatever else follows. Thanks. >> (mapatoms (lambda (atom) >> (when (string= (symbol-name atom) >> "xyzw") >> (error "Found %s" atom)))) > > Well, you wrote xýzw rather than xyzw above. But even if you didn't, as > long as nothing else interned 'xyzw in some manner, such a symbol would > not get found. Shit. There is shit on my screen, I did not see that ý. I should keep the screen more clean ;-) ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: eval trouble [not found] ` <mailman.17522.1219697977.18990.help-gnu-emacs@gnu.org> 2008-08-25 21:36 ` David Kastrup @ 2008-09-14 20:57 ` David Combs 2008-09-14 22:20 ` Drew Adams 1 sibling, 1 reply; 15+ messages in thread From: David Combs @ 2008-09-14 20:57 UTC (permalink / raw) To: help-gnu-emacs [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 1467 bytes --] In article <mailman.17522.1219697977.18990.help-gnu-emacs@gnu.org>, Lennart Borgman (gmail) <lennart.borgman@gmail.com> wrote: >David Kastrup wrote: >> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: >> >>> Pascal J. Bourguignon wrote: >>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes: >>>>>> 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? >>>> eval doesn't care, but how would you be able to refer again to the >>>> defined thing if you don't have its name in some dictionary? >>> >>> Thanks. I see. I thought eval interned the symbol, or perhaps rather >>> created an interned symbol. In this case it does not do that. >> >> Eval _does_ create an interned symbol. But it is not EQ to the unique >> uninterned symbol that make-symbol creates. >> > >I am a bit confused, but I guess you mean if the symbol does not exist: > >(let ((sym (make-symbol "xýzw"))) > (eval `(progn (setq ,sym 1) > (put ',sym 'some 'value)))) > >(mapatoms (lambda (atom) > (when (string= (symbol-name atom) > "xyzw") > (error "Found %s" atom)))) > > > Please, why the comma before sym -- quoted, no less: > (put ',sym 'some 'value)))) Thanks! David ^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: eval trouble 2008-09-14 20:57 ` David Combs @ 2008-09-14 22:20 ` Drew Adams 2008-09-17 7:51 ` Kevin Rodgers [not found] ` <mailman.19402.1221638109.18990.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 15+ messages in thread From: Drew Adams @ 2008-09-14 22:20 UTC (permalink / raw) To: 'David Combs', help-gnu-emacs > Please, why the comma before sym -- quoted, no less: > > (put ',sym 'some 'value)))) See the Emacs manual, node Backquote. Inside a backquote (`): ,sym evaluates sym and uses that value. ' then wraps that in (quote ...) So if the value of sym is hello, then ,sym gives hello and ',sym gives 'hello. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: eval trouble 2008-09-14 22:20 ` Drew Adams @ 2008-09-17 7:51 ` Kevin Rodgers [not found] ` <mailman.19402.1221638109.18990.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 15+ messages in thread From: Kevin Rodgers @ 2008-09-17 7:51 UTC (permalink / raw) To: help-gnu-emacs Drew Adams wrote: >> Please, why the comma before sym -- quoted, no less: >>> (put ',sym 'some 'value)))) > > See the Emacs manual, node Backquote. > > Inside a backquote (`): > ,sym evaluates sym and uses that value. > ' then wraps that in (quote ...) > > So if the value of sym is hello, > then ,sym gives hello and ',sym gives 'hello. As does (quote ,sym) -- Kevin Rodgers Denver, Colorado, USA ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.19402.1221638109.18990.help-gnu-emacs@gnu.org>]
* Re: eval trouble [not found] ` <mailman.19402.1221638109.18990.help-gnu-emacs@gnu.org> @ 2008-09-22 19:59 ` David Combs 0 siblings, 0 replies; 15+ messages in thread From: David Combs @ 2008-09-22 19:59 UTC (permalink / raw) To: help-gnu-emacs In article <mailman.19402.1221638109.18990.help-gnu-emacs@gnu.org>, Kevin Rodgers <kevin.d.rodgers@gmail.com> wrote: >Drew Adams wrote: >>> Please, why the comma before sym -- quoted, no less: >>>> (put ',sym 'some 'value)))) >> >> See the Emacs manual, node Backquote. >> >> Inside a backquote (`): >> ,sym evaluates sym and uses that value. >> ' then wraps that in (quote ...) >> >> So if the value of sym is hello, >> then ,sym gives hello and ',sym gives 'hello. > >As does (quote ,sym) > >-- >Kevin Rodgers >Denver, Colorado, USA I guess I need some more caffein (or sleep)! THANKS! David ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: eval trouble [not found] ` <mailman.17509.1219684131.18990.help-gnu-emacs@gnu.org> 2008-08-25 17:43 ` Pascal J. Bourguignon @ 2008-08-25 19:48 ` David Kastrup 1 sibling, 0 replies; 15+ messages in thread From: David Kastrup @ 2008-08-25 19:48 UTC (permalink / raw) To: help-gnu-emacs "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> 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 like (eq 1.0 1.0) -> nil creates two different objects which are not EQ. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2008-09-22 19:59 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-08-25 16:56 eval trouble Lennart Borgman (gmail) 2008-08-25 17:08 ` Lennart Borgman (gmail) [not found] ` <mailman.17509.1219684131.18990.help-gnu-emacs@gnu.org> 2008-08-25 17:43 ` Pascal J. Bourguignon 2008-08-25 17:45 ` Lennart Borgman (gmail) 2008-08-25 18:47 ` Pascal J. Bourguignon 2008-08-25 18:34 ` Lennart Borgman (gmail) [not found] ` <mailman.17512.1219686348.18990.help-gnu-emacs@gnu.org> 2008-08-25 19:50 ` David Kastrup 2008-08-25 20:59 ` Lennart Borgman (gmail) [not found] ` <mailman.17522.1219697977.18990.help-gnu-emacs@gnu.org> 2008-08-25 21:36 ` David Kastrup 2008-08-25 21:43 ` Lennart Borgman (gmail) 2008-09-14 20:57 ` David Combs 2008-09-14 22:20 ` Drew Adams 2008-09-17 7:51 ` Kevin Rodgers [not found] ` <mailman.19402.1221638109.18990.help-gnu-emacs@gnu.org> 2008-09-22 19:59 ` David Combs 2008-08-25 19:48 ` David Kastrup
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).