From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Working with constansts Date: Mon, 18 May 2009 14:20:50 +0200 Organization: Anevia SAS Message-ID: <7c7i0e8uvx.fsf@pbourguignon.anevia.com> References: <87d4ahylp3.fsf@galatea.local> <000801c9d191$22a21340$0200a8c0@us.oracle.com> <874ovszuu3.fsf@galatea.local> <87zldkxicx.fsf@galatea.local> <7ceiuuczad.fsf@pbourguignon.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1242650448 11989 80.91.229.12 (18 May 2009 12:40:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 May 2009 12:40:48 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 18 14:40:41 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1M6291-0002Zz-3J for geh-help-gnu-emacs@m.gmane.org; Mon, 18 May 2009 14:40:39 +0200 Original-Received: from localhost ([127.0.0.1]:54722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M6290-0006OD-4S for geh-help-gnu-emacs@m.gmane.org; Mon, 18 May 2009 08:40:38 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!cleanfeed3-a.proxad.net!nnrp7-1.free.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:OGQ1YTk4MDVhZjFiNzQ2NGFjNzBmYmE0NGUwZDEyNDkwNzYyNmRlYg== Original-Lines: 69 Original-NNTP-Posting-Date: 18 May 2009 14:20:51 MEST Original-NNTP-Posting-Host: 88.170.236.224 Original-X-Trace: 1242649251 news-2.free.fr 21839 88.170.236.224:44477 Original-X-Complaints-To: abuse@proxad.net Original-Xref: news.stanford.edu gnu.emacs.help:169289 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:64537 Archived-At: Nikolaj Schumacher writes: > pjb@informatimago.com (Pascal J. Bourguignon) wrote: > >>> And in fact, you can cast constness away in C++, so it really has >>> nothing to do with execution versus compile time. It's just a helper >>> for the developer to prevent side-effects. >> >> However, the C or C++ compilers are allowed to consider that the value >> of the constant won't change, so they may inline any number of copies >> they want. > > Yes, I was thinking of const references... And in lisp, consts would > actually be references (maybe with the exception of numbers) > > (defconst x '(foo . bar) > > We've talked about (setq x 'foo) being illegal, but that would not > prevent (setcar x 'bar). And even if you prevent that, you can have: > > (defvar y '(foo . bar) > (defconst x y) > > Now the compiler cannot assume that y will not change, it's just a > reminder to the developer. Well, you shouldn't modify quoted literals either, since this is modifying the program: (defun f (x) (let ((y '(foo . bar))) (prog1 (car y) (setf (car y) x)))) (list (f 1) (f 2) (f 3) (symbol-function 'f)) --> (foo 1 2 (lambda (x) (let ((y (quote (3 . bar)))) (prog1 (car y) (setf (car y) x))))) But what you say is correct, in the case of: (defvar y (cons 'foo 'bar)) (defconst x y) >>> There really is no pressing requirement for the current behavior, the >>> run-time just doesn't verify it. >> >> Nothing would prevent emacs lisp to specify defconst in such a way the >> byte compiler could do the same. Only in the case of emacs it's more >> practical to change the value of the constant, because it means that >> you can modify your program without having to restart emacs, which is >> a good thing in the case of an editor/IDE/OS. > > And nothing would prevent the byte-compiler (and eval-last-sexp) to have > special privileges for overriding consts in a live environment. (You > don't have to format a disk to reclaim write-protected files, either.) > > Certainly, inconsistencies might appear, unless every function inlining > the value is also re-evaluated. But that's also the case with macros. > > > > regards, > Nikolaj Schumacher -- __Pascal Bourguignon__