all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs Devel <emacs-devel@gnu.org>
Subject: Re: Real constants
Date: Wed, 13 Jul 2005 22:25:40 -0400	[thread overview]
Message-ID: <877jfum8rb.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <f7ccd24b050713112951159a79@mail.gmail.com> (Juanma Barranquero's message of "Wed, 13 Jul 2005 20:29:52 +0200")

> Yeah, I meant "trivial now", of course. But that's been in Emacs for
> what? Five years?

There's no released Emacs with defvaralias, so it's still recent.

>> Among the local patches I use, I've expanded this `constant' field to
>> 2 bits, so it can be either hard-read-only or soft-read-only (or writable,
>> of course).  The soft-read-only state is used by defconst so that variables
>> defined by defconst cannot be setq but can be changed via defconst
>> (important when you reload a new version of a package where a defconst was
>> changed).

> Do you allow un-const'ing things?

No.  But I could make `defvar' un-const a defconst if that's necessary.

> If so, special care should be taken with `enable-multibyte-characters',
> nil, t and perhaps a few others...

These are hard-read-only so they can't be redefined with defconst
or un-const'd.

>> Making defconst variables into constants introduces a few occasional
>> problems with some packages, of course, but nothing too hard to fix.

> And in fact I'd bet most of these problems are, if not bugs, at least
> bad style... :)

Yes, most.  But for some the fix is not too elegant either.
Typical problems:

- The const-value can't be conveniently constructed at top-level:

   (defvar foo nil)
   (defvar bar nil)
   (let ((blabla))
     (setq foo (toto blabla))
     (setq bar (toto blabla)))

  Removing the defvars and replacing the setq with defconst is correct, but
  the byte-compiler is a bit dumb and don't realize that foo and bar are
  both unconditionally defined, so it may warn of unknown variables.

- name clashes.  E.g.

    (defconst e 2.718281828459045)
  ...
    (let ((b (match-beginning 0))
          (e (match-end 0)))
  ...

- there are also other cases where a const-var is not quite constant: some
  part of the code (or some advice, or hook) wants to temporarily let-bind
  it to some other value.

> Could you please post your code here? I think it would be a great
> feature (after 22.1).

I doubt it'll ever make its way into Emacs: it introduces compatibility
problems without bringing any clear benefit.


        Stefan

  reply	other threads:[~2005-07-14  2:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877jfum8rb.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /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 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.