Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: Linda Walsh Newsgroups: gnu.bash.bug Subject: Re: language inconsistency(wart) & RFE Date: Wed, 21 Oct 2015 15:53:24 -0700 Lines: 58 Approved: bug-bash@gnu.org Message-ID: References: <5621A1DD.90205@tlinx.org> <56226F73.4040908@tlinx.org> <20151019124228.GT27325@eeg.ccf.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1445468021 28424 208.118.235.17 (21 Oct 2015 22:53:41 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash To: Greg Wooledge Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird In-Reply-To: <20151019124228.GT27325@eeg.ccf.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11735 Greg Wooledge wrote: --- please note locations of 'auto_local' > # at beginning.... > shopt -s auto_local > # Pick unbiased random number from 0 to N-1 ($1 = N) > # Returns value in variable r. > rand() { > shopt -u auto_local > local max=$((32768 / $1 * $1)) > while (( (r=$RANDOM) >= max )); do :; done > r=$(( r % $1 )) > shopt -s auto_local > } > > 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. ---- Under my proposal, it is a shopt option that can be turned on or off. When it is off, things behave as they do no. When it is on, vars w/o a specific declarator, or declarator+"-g switch" would be default to be local. > (If you want to attack "language warts", start with the inability to > return values from functions to their callers!) --- They can -- unfortunately, it is by printing to, usually, to stdout, and reading it in the parent (I agree this is a rather roundabout and inefficient way to send return vals... I've thought about that, but running into inconsistencies in the dynamic variable propagation. It's hard to define an "alternate syntax" when the primary syntax doesn't consistently yield the same answer. So need to figure that out first. Hopefully the toggling of 'auto_local' isn't hard to understand: it's like adding a -i or -l flag to var declaration -- doesn't affect current values in vars, but only new assignments.