From: Juanma Barranquero <lekktu@gmail.com>
Subject: defvar'ing constants
Date: Fri, 24 Jun 2005 05:54:41 +0200 [thread overview]
Message-ID: <f7ccd24b05062320549d539e2@mail.gmail.com> (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
next reply other threads:[~2005-06-24 3:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-24 3:54 Juanma Barranquero [this message]
2005-06-25 0:31 ` defvar'ing constants 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f7ccd24b05062320549d539e2@mail.gmail.com \
--to=lekktu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).