unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Real constants
@ 2005-07-13 13:59 Juanma Barranquero
  2005-07-13 18:14 ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Juanma Barranquero @ 2005-07-13 13:59 UTC (permalink / raw)


This is *not* a proposed change for 22.1; more of a question about a
feature, or lack of it.

Having the possibility of marking a symbol as constant (not in the
`defconst' sense, but really constant) seems so potentially useful and
so trivial to implement (vide the attached patch), that I can only
suppose there's some reason, or perceived problem, not to have done it
till now.

Could someone please explain the rationale for not having true
constants in elisp?

Thanks,

                    /L/e/k/t/u



Index: src/eval.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/eval.c,v
retrieving revision 1.250
diff -u -2 -r1.250 eval.c
--- src/eval.c	13 Jul 2005 05:31:35 -0000	1.250
+++ src/eval.c	13 Jul 2005 13:49:29 -0000
@@ -956,4 +956,37 @@
     }
 }
+
+DEFUN ("set-constant-p", Fset_constant_p, Sset_constant_p, 2, 2, 0,
+       doc: /* Set constant state of SYMBOL to FLAG.
+When FLAG is non-nil, SYMBOL becomes constant; otherwise, it is variable.
+Keywords, ie symbols satisfying `keywordp', are always constant.  */)
+     (symbol, flag)
+     Lisp_Object symbol, flag;
+{
+  CHECK_SYMBOL (symbol);
+
+  if (EQ (Fkeywordp (symbol), Qt))
+    error ("Cannot change constant state of keyword `%s'",
+           SDATA (SYMBOL_NAME (symbol)));
+
+  XSYMBOL (symbol)->constant = EQ (flag, Qt);
+
+  return symbol;
+}
+
+DEFUN ("constantp", Fconstantp, Sconstantp, 1, 1, 0,
+       doc: /* Return t if SYMBOL is a constant.
+If so, its value cannot be changed.
+The `constant'ness of a symbol can be changed with `set-constant-p'.  */)
+     (symbol)
+     Lisp_Object symbol;
+{
+  CHECK_SYMBOL (symbol);
+
+  if (XSYMBOL (symbol)->constant)
+    return Qt;
+  return Qnil;
+}
+
 \f
  DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
@@ -3561,4 +3594,6 @@
   defsubr (&Sdefconst);
   defsubr (&Suser_variable_p);
+  defsubr (&Sset_constant_p);
+  defsubr (&Sconstantp);
   defsubr (&Slet);
   defsubr (&SletX);

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

end of thread, other threads:[~2005-07-18  6:05 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-13 13:59 Real constants Juanma Barranquero
2005-07-13 18:14 ` Stefan Monnier
2005-07-13 18:29   ` Juanma Barranquero
2005-07-14  2:25     ` Stefan Monnier
2005-07-14  8:05       ` Juanma Barranquero
2005-07-14  3:14     ` Richard M. Stallman
2005-07-14  8:16       ` Juanma Barranquero
2005-07-15  0:12         ` Richard M. Stallman
2005-07-15  0:53           ` Juanma Barranquero
2005-07-15  9:47             ` Thien-Thi Nguyen
2005-07-15 22:03               ` Richard M. Stallman
2005-07-16 10:10                 ` Juanma Barranquero
2005-07-15 18:10             ` Richard M. Stallman
2005-07-15  4:24         ` Stefan Monnier
2005-07-18  6:05           ` Juanma Barranquero

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