all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* defconst
@ 2004-11-18  0:21 Luc Teirlinck
  2004-11-18  0:36 ` defconst Drew Adams
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Luc Teirlinck @ 2004-11-18  0:21 UTC (permalink / raw)


I wonder what the exact usefulness of defconst, in its present form,
is.  It does two things, one very concrete, the other rather vague
(and therefore not very useful).

The concrete effect of `(defconst var value)' is that it is equivalent
with `(defvar var value)' followed by `(setq var value)', that is, its
concrete effect is that of the CL function `defparameter'.

Apart from that, quoted from `(elisp)Defining Variables':

     This special form defines SYMBOL as a value and initializes it.
     It informs a person reading your code that SYMBOL has a standard
     global value, established here, that should not be changed by the
     user or by other programs.

There are two problems with this.

Firstly, it does not inform everybody that needs to be informed.  It
informs the person reading the defconst directly, and the person
writing Elisp code, _who compiles and pays attention to compiler
warnings_, through a compiler warning.  It does not inform the user
who changes the value in his .emacs or interactively that he is doing
something that may have adverse consequences.  It does not inform the
`C-h v' user.

Secondly, one can not rely on what the information concretely means.
Many people use defconst just because they do not consider it _very
likely_ that somebody might want to change the value of the variable.

I believe it would be better if `defconst' behaved like `defconstant'
in CLISP: throw an error if the user or a program tries to change the
value through anything else but a second defconst.  If a second
defconst resets the "constant" to a different value, give a warning,
but change the constant's value anyway.  Do not warn about a defconst
that keeps the value the same.  (Note that this is CLISP specific
behavior.  CL leaves most of the `defconstant' behavior up to the
implementation.)

This way, everybody who tries to change the value gets informed of the
fact that it might cause trouble and still gets the chance to do it
anyway (but knowing the risk).  It would allow programmers seeing a
defconst to rely on the fact that the value they see in the defconst
is the value they will get if they evaluate the symbol.  Currently,
they can not do that.  `defconst' would produce something `read-only'
which it currently does not.

Maybe it might not be advisable to make such a change before the
release, but what about after it?  I bring it up now, because a
decision on this might affect what we do with current defconst's.

Sincerely,

Luc.








 LocalWords:  defconst's

^ permalink raw reply	[flat|nested] 7+ messages in thread
* defconst
@ 2004-11-14 18:33 Luc Teirlinck
  2004-11-15 14:00 ` defconst Richard Stallman
  0 siblings, 1 reply; 7+ messages in thread
From: Luc Teirlinck @ 2004-11-14 18:33 UTC (permalink / raw)
  Cc: Rob Riepel, Michael Kifer, Kyle Jones

I believe that `defconst' is a relatively widely misused function.  I
believe that it should only be used for something that is an absolute
constant.  Yet people seem to use it for such things as variables that
should only be changed by the user but not by Lisp code, or vice-versa,
or variables that have no effect when changed with setq (but only if a
function is called), and any other of a number of situations where
changing the value of a variable has to be done carefully, or only in
certain situations.

Using `defconst' instead of `defvar' is much more than just a
stylistic error.  If the file gets reloaded, then the defconst, unlike
defvar, will override any changes made thus far in the Elisp session,
behind the user's back.  This can be very confusing to the user.
Thus, it should only be used if _any_ change to the variable in any
way would be wrong.  If in doubt, I believe one should always use defvar.

Maybe `defconst' is OK for version numbers.  They are not necessarily
constants, but if a new version of a package is loaded, the old
version number should indeed be overridden.

I only will handle uses of defconst that produced compiler warnings.
I am afraid that the problem is more widespread.

Compiler warnings are produced by defconsts in the viper package,
cust-print.el, tpu-edt.el, life.el and lao.el.

It appears that the vast majority of the many defconsts in the viper
package should be defvar's.  I hope that the author of viper.el still
maintains the package and can take a look at this.

For the four other files, I will propose concrete changes.

I CC-ed the authors of the viper, tpu-edt and life packages. 


Sincerely,

Luc.

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

end of thread, other threads:[~2004-11-20  1:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-18  0:21 defconst Luc Teirlinck
2004-11-18  0:36 ` defconst Drew Adams
2004-11-18  1:17 ` defconst Stefan
2004-11-19  2:25 ` defconst Richard Stallman
2004-11-20  1:25   ` defconst Luc Teirlinck
  -- strict thread matches above, loose matches on Subject: below --
2004-11-14 18:33 defconst Luc Teirlinck
2004-11-15 14:00 ` defconst Richard Stallman

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.