From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Real constants Date: Wed, 13 Jul 2005 22:25:40 -0400 Message-ID: <877jfum8rb.fsf-monnier+emacs@gnu.org> References: <87u0iymvce.fsf-monnier+emacs@gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1121308254 31101 80.91.229.2 (14 Jul 2005 02:30:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 14 Jul 2005 02:30:54 +0000 (UTC) Cc: Emacs Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 14 04:30:51 2005 Return-path: Original-Received: from mail-relay.eunet.no ([193.71.71.242]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DstU7-0001Oc-Uj for ged-emacs-devel@gmane.org; Thu, 14 Jul 2005 04:30:00 +0200 Original-Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by mail-relay.eunet.no (8.13.1/8.13.1/GN) with ESMTP id j6E2TxQm016141 for ; Thu, 14 Jul 2005 04:29:59 +0200 (CEST) (envelope-from emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org) Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DstVo-00063y-5Q for ged-emacs-devel@m.gmane.org; Wed, 13 Jul 2005 22:31:44 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DstVE-0005zP-5V for emacs-devel@gnu.org; Wed, 13 Jul 2005 22:31:08 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DstV7-0005u5-IA for emacs-devel@gnu.org; Wed, 13 Jul 2005 22:31:02 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DstV7-0005sf-2n for emacs-devel@gnu.org; Wed, 13 Jul 2005 22:31:01 -0400 Original-Received: from [209.226.175.110] (helo=tomts43-srv.bellnexxia.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DstXu-0004Hr-Ll for emacs-devel@gnu.org; Wed, 13 Jul 2005 22:33:54 -0400 Original-Received: from alfajor ([67.71.25.244]) by tomts43-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20050714022540.LLLA2981.tomts43-srv.bellnexxia.net@alfajor>; Wed, 13 Jul 2005 22:25:40 -0400 Original-Received: by alfajor (Postfix, from userid 1000) id 9EAFAD7571; Wed, 13 Jul 2005 22:25:40 -0400 (EDT) Original-To: Juanma Barranquero In-Reply-To: (Juanma Barranquero's message of "Wed, 13 Jul 2005 20:29:52 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:40873 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:40873 > 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