help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Working with constansts


From: Pascal J. Bourguignon
Subject: Re: Working with constansts
Date: Mon, 11 May 2009 08:29:34 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)

Richard Riley <rileyrgdev@googlemail.com> writes:

> Which was basically my original question.
>
> If you go to the bother of having a "const xyz" implementation then it
> seems to me slightly silly not to enforce it.
>
> Of course I understand if the answer is "history and that's the way it
> is" but I would sympathise with a new programmer to Lisp that is
> surprised he can modify a "const" especially if he came from a C/C++
> background where we all fully understand WHY consts are useful for the
> programmer but the compiler also enforced it.

The important point is that a lisp system is being programmed at the
same time it is executed.  Therefore redefining a constant may be
taken into account, because it may be what the _programmer_ really
means.

In C, you would have to recompile the program before a change to a
constant is taken into account, but it would be very possible to
modify a constant: nothing prevents you to edit the C sources,
recompile and relaunch.

Some lisps (such as SBCL) do indeed issue a warning (actually a
continuable error) when you try to change a constant.




Usually, we apply a convention of naming constants surrounding them
with + signs:

   (defconst +xyz+ 42)

so you notice immediately if you're doing something you don't mean
when you write:

   (setq +xyz+ ...)

This low-tech solution is good enough, so there's no much point in
implementing further tests in the implementation.

(But unfortunately, these conventions are not often respected in emacs
lisp code).  
-- 
__Pascal Bourguignon__


reply via email to

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