bug-bash
[Top][All Lists]
Advanced

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

Re: static vs. dynamic scoping


From: Chet Ramey
Subject: Re: static vs. dynamic scoping
Date: Tue, 09 Nov 2010 23:00:47 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2

On 11/9/10 4:52 PM, Eric Blake wrote:
> On the Austin Group mailing list, David Korn (of ksh93 fame)
> complained[1] that bash's 'local' uses dynamic scoping, but that ksh's
> 'typeset' uses static scoping, and argued that static scoping is saner
> since it matches the behavior of declarative languages like C and Java
> (dynamic scoping mainly matters in functional languages like lisp):
> 
> [1]
> https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=14951
> 
> I'm trying to standardize the notion of local variables for the next
> revision of POSIX, but before I can do so, I need some feedback on two
> general aspects:
> 
> 1. Implementation aspect:
>   How hard would it be to add static scoping to bash?
>   Is it something that can be added in addition to dynamic scoping, via
> the use of an option to select the non-default mode (for example, 'local
> -d' to force dynamic, 'local -s' to force static, and 'local' to go with
> default scoping)?

The scoping is at the function level, not the variable level, so this
would not be possible without more work than I'd be willing to do.

>   If both scoping forms are supported, is it worth making the default
> scoping dependent on posix compliance (for example, 'local' means
> dynamic scoping for 'set +o posix' but static scoping for 'set -o
> posix'), or should it be the same default for both modes?

I really don't want to have "posix" and "non-posix" functions with
different behaviors.  The fact that ksh93 has those is an awful feature.

Chet
-- 
``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/



reply via email to

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