unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* defvar'ing constants
@ 2005-06-24  3:54 Juanma Barranquero
  2005-06-25  0:31 ` Richard M. Stallman
  0 siblings, 1 reply; 12+ messages in thread
From: Juanma Barranquero @ 2005-06-24  3:54 UTC (permalink / raw)


*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (defvar :k)
:k
ELISP> (defvar :k 1)
:k
ELISP> (defconst :k 1)
*** Eval error ***  Attempt to set a constant symbol: :k
ELISP> (set :k :k)
:k
ELISP> (set :k 1)
*** Eval error ***  Attempt to set a constant symbol: :k
ELISP> (set-default :k :k)
:k
ELISP> (set-default :k 1)
*** Eval error ***  Attempt to set a constant symbol: :k
ELISP> 

For consistency:

  (defvar CONSTANT)               ; should work
  (defvar CONSTANT ITS-VALUE)     ; should work
  (defvar CONSTANT OTHER-VALUE)   ; should fail

The attached patch implements this behavior.  I'm calling error
directly, copying the error message from set_internal; another idea
would be to allow the call to Fset_default to go through when

   NILP (tem) ||
   (SYMBOL_CONSTANT_P (sym) && !EQ (tem, tail))

which avoid duplicating the error checking and the message, but
doesn't seem clean to me.  Opinions?

-- 
                    /L/e/k/t/u


Index: src/eval.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/eval.c,v
retrieving revision 1.243
diff -u -2 -r1.243 eval.c
--- src/eval.c	23 Jun 2005 16:07:51 -0000	1.243
+++ src/eval.c	24 Jun 2005 03:42:47 -0000
@@ -793,4 +793,8 @@
       if (NILP (tem))
  	Fset_default (sym, Feval (Fcar (tail)));
+      else if (SYMBOL_CONSTANT_P (sym)
+               && !EQ (tem, tail))
+        error ("Attempt to set a constant symbol: %s",
+               SDATA (SYMBOL_NAME (sym)));
       else
 	{ /* Check if there is really a global binding rather than just a let

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-08-01 16:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-24  3:54 defvar'ing constants Juanma Barranquero
2005-06-25  0:31 ` Richard M. Stallman
2005-06-25  4:14   ` Jay Belanger
2005-06-25 13:05     ` Juanma Barranquero
2005-06-25 21:31     ` David Kastrup
2005-06-26  2:28       ` Jay Belanger
2005-08-01  1:39         ` Stephen J. Turnbull
2005-08-01 16:46           ` Richard M. Stallman
2005-06-25 12:59   ` Juanma Barranquero
2005-06-28  5:06   ` Stefan Monnier
2005-06-28  7:40     ` Juanma Barranquero
2005-06-28 21:29     ` Richard M. Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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