emacs-devel
[Top][All Lists]
Advanced

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

Real constants


From: Juanma Barranquero
Subject: Real constants
Date: Wed, 13 Jul 2005 15:59:13 +0200

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;
+}
+
 
  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);




reply via email to

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