Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #11704
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Greg Wooledge <wooledg@eeg.ccf.org> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: language inconsistency(wart) & RFE |
| Date | Mon, 19 Oct 2015 08:42:28 -0400 |
| Lines | 49 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.632.1445258558.7904.bug-bash@gnu.org> (permalink) |
| References | <5621A1DD.90205@tlinx.org> <CAAZkfoJzXL_Gc0onFJDnfmHujSTfi=pWte-gsw5k5n24mveKOw@mail.gmail.com> <56226F73.4040908@tlinx.org> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Trace | usenet.stanford.edu 1445258558 13032 208.118.235.17 (19 Oct 2015 12:42:38 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | bug-bash <bug-bash@gnu.org> |
| To | Linda Walsh <bash@tlinx.org> |
| Envelope-to | bug-bash@gnu.org |
| Content-Disposition | inline |
| In-Reply-To | <56226F73.4040908@tlinx.org> |
| User-Agent | Mutt/1.4.2.3i |
| X-detected-operating-system | by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] |
| X-Received-From | 139.137.100.1 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.14 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <http://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| Xref | csiph.com gnu.bash.bug:11704 |
Show key headers only | View raw
On Sat, Oct 17, 2015 at 08:55:31AM -0700, Linda Walsh wrote:
> If I needed a way to declare something global, yes...
> But what I am wanting is a way to allow changing the defaults
> of the implicit variable creation (which could still be
> explicitly declared with "-g" if one wanted their result to be
> made global.
So you are basically saying you want all of your function variables
to be local, but you are too lazy to write 'local i j k' and you want
bash to do it for you?
Also I think you are completely misrepresenting the dynamic variable
scope system that bash uses. Variables are not just global or local.
There's an entire stack of them. When you reference a variable (let's
say i) inside a function, bash searches up through the call stack
looking for a variable named i until it finds one.
Since functions cannot return values to their callers, the entire system
of "put values into an upper-scope variable so the caller can see them"
would break if your proposal of automatic localization were to be
adopted.
# Pick unbiased random number from 0 to N-1 ($1 = N)
# Returns value in variable r.
rand() {
local max=$((32768 / $1 * $1))
while (( (r=$RANDOM) >= max )); do :; done
r=$(( r % $1 ))
}
foo() {
local r
rand 6
echo "I rolled $((r+1))"
}
foo
# r is not visible here
Under your proposal, the variable r which is defined locally in foo, and
is up-scope-visible to rand (so that rand can put a return value into
it), would also be defined locally within r, so there would be no way to
return a value from rand to foo.
(If you want to attack "language warts", start with the inability to
return values from functions to their callers!)
Back to gnu.bash.bug | Previous | Next | Find similar
Re: language inconsistency(wart) & RFE Greg Wooledge <wooledg@eeg.ccf.org> - 2015-10-19 08:42 -0400
csiph-web