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: Tue, 12 May 2009 13:43:52 +0200
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux)

Nikolaj Schumacher <me@nschum.de> writes:

> Richard Riley <rileyrgdev@googlemail.com> wrote:
>
>>> Because this would incur overhead on every assignment, as it would have 
>>> to check whether the variable being assigned was declared as a constant.  
>>> Since this is so rarely the case, this overhead could be seen as mostly 
>>> wasted and unnecessary.
>>
>> I don't know enough about Lisp than I can only assume that in this case
>> it can not be detected at compile time IF you compile to byte/p code.
>
> "Thanks" to dynamic scoping it cannot be caught at compile time.
>
> (defconst xxx nil)
>
> (defun change-xxx ()
>   (setx xxx t)) ;; const or variable?
>
> (let ((xxx nil))
>   (change-xxx))

It could be caught, if it was so defined by the language.

For example, in the case of Common Lisp, it is forbidden to rebind
lexically or dynamically a constant.

    The consequences are undefined when constant symbols are rebound
    as either lexical or dynamic variables. In other words, a
    reference to a symbol declared with defconstant always refers to
    its global value.



Again, in both languages, a good solution is to mark constants with
plus signs, so you're not tempted to rebind them.


-- 
__Pascal Bourguignon__


reply via email to

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