[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 <chris@chrisdown.name> 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 chet@case.edu http://cnswww.cns.cwru.edu/~chet/
- Re: Local variables overriding global constants, (continued)
- Re: Local variables overriding global constants, Chris Down, 2013/04/03
- Re: Local variables overriding global constants, Nikolai Kondrashov, 2013/04/03
- Re: Local variables overriding global constants, Chris Down, 2013/04/03
- Re: Local variables overriding global constants, Pierre Gaston, 2013/04/03
- Re: Local variables overriding global constants, Pierre Gaston, 2013/04/03
- Re: Local variables overriding global constants, Nikolai Kondrashov, 2013/04/03
- Re: Local variables overriding global constants, Chris F.A. Johnson, 2013/04/03
- Re: Local variables overriding global constants, Pierre Gaston, 2013/04/03
- Re: Local variables overriding global constants, Chris F.A. Johnson, 2013/04/03
- Re: Local variables overriding global constants, Pierre Gaston, 2013/04/03
- Re: Local variables overriding global constants,
Chet Ramey <=
- Re: Local variables overriding global constants, Mike Frysinger, 2013/04/03
- Re: Local variables overriding global constants, Chet Ramey, 2013/04/03
- Re: Local variables overriding global constants, Mike Frysinger, 2013/04/04
- Re: Local variables overriding global constants, Chet Ramey, 2013/04/04
- Re: Local variables overriding global constants, Mike Frysinger, 2013/04/04
- Re: Local variables overriding global constants, Chris F.A. Johnson, 2013/04/03