bug-bash
[Top][All Lists]
Advanced

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

Re: Local variables overriding global constants


From: Chet Ramey
Subject: Re: Local variables overriding global constants
Date: Wed, 03 Apr 2013 09:34:18 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130307 Thunderbird/17.0.4

On 4/3/13 4:21 AM, Pierre Gaston wrote:
> On Wed, Apr 3, 2013 at 11:03 AM, Chris Down <address@hidden> wrote:
> 
>> On 2013-04-03 11:00, Nikolai Kondrashov wrote:
>>>>>> It doesn't work because you are trying to redefine an existing
>>>>>> readonly variable.
>>>>>
>>>>> Yes, but I'm explicitly redefining it locally, only for this function.
>>>>> And this works for variables previously defined in the calling
>> function.
>>>>
>>>> You're not redefining it locally, you are unsuccessfully trying to
>> override a
>>>> global.
>>>
>>
> Still Nikolai has a point.
> It's not clear why readonly variable can be overridden when the variable is
> declared readonly in the scope of an englobing function but not if it is
> declared readonly in the global scope.

A variable is declared readonly for a reason, and, since readonly variables
may not be assigned to, I don't believe you should be able to override a
readonly variable by declaring it local to a function.  I did, however
reluctantly, allow a way to do this by permitting a function writer to
override local readonly variables (given bash's dynamic scoping) or to
override global readonly variables when several levels down in the call
stack.

The current behavior is a compromise.  Compromises always come back to
bite you because the inconsistencies that result are more trouble than
the flexibility they offer is worth.

> I seem to recall this has been discussed on this list at some point)

Quite a few times.  Try

http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00105.html
http://lists.gnu.org/archive/html/bug-bash/2012-04/msg00073.html

It's about time for the discussion to happen again.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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