emacs-devel
[Top][All Lists]
Advanced

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

defvar'ing constants


From: Juanma Barranquero
Subject: defvar'ing constants
Date: Fri, 24 Jun 2005 05:54:41 +0200

*** 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




reply via email to

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