From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18629 invoked from network); 19 Jul 2003 02:07:05 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 19 Jul 2003 02:07:05 -0000 Received: (qmail 5640 invoked by alias); 19 Jul 2003 02:06:50 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 18870 Received: (qmail 5614 invoked from network); 19 Jul 2003 02:06:50 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 19 Jul 2003 02:06:50 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [216.27.190.146] by sunsite.dk (MessageWall 1.0.8) with SMTP; 19 Jul 2003 2:6:50 -0000 Received: from ceramic.fifi.org (mail@ceramic.fifi.org [216.27.190.147]) by tantale.fifi.org (8.9.3p2/8.9.3/Debian 8.9.3-21) with ESMTP id TAA29532 for ; Fri, 18 Jul 2003 19:06:49 -0700 Received: from phil by ceramic.fifi.org with local (Exim 3.35 #1 (Debian)) id 19dh7Y-0004Tr-00 for ; Fri, 18 Jul 2003 19:06:48 -0700 To: zsh-workers@sunsite.dk Subject: Mysteriously changing parameters and options within a function. Mail-Copies-To: nobody From: Philippe Troin Date: 18 Jul 2003 19:06:48 -0700 Message-ID: <87smp346dj.fsf@ceramic.fifi.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: Philippe Troin Consider the following function whose purpose is mostly evident: check-missing-locals() { local -A parms_before options_before ignored_params local i xit xit=0 ignored_params=(parms_before 1 options_before 1 parameters 1 i 1 xit 1 parameters 1 functions 1 aliases 1 galiases 1 history 1 historywords 1 widgets 1 options 1 modules 1 LINENO 1 ERRNO 1 RANDOM 1 TTYIDLE 1 SECONDS 1 status 1 '?' 1 _ 1 pipestatus 1 ) for i in ${(k)parameters} do (( $+ignored_params[$i] )) && continue parms_before[$i]=${(P)i} done options_before=(${(kv)options}) eval $* for i in ${(ko)options} do if [[ $options[$i] != $options_before[$i] ]] then echo "$0: changed option $i: $options_before[$i] " \ "vs. $options[$i]" 1>&2 xit=1 fi done for i in ${(ko)parms_before} do (( $+ignored_params[$i] )) && continue if (( ! $+parameters[$i] )) then echo "$0: unset parameter $i" 1>&2 xit=1 fi done for i in ${(ko)parameters} do (( $+ignored_params[$i] )) && continue if (( ! $+parms_before[$i] )) then echo "$0: set parameter $i" 1>&2 xit=1 fi done for i in ${(ko)parms_before} do (( $+ignored_params[$i] )) && continue if (( $+parameters[$i] && $+parms_before[$i] )) \ && [[ ${(P)i} != $parms_before[$i] ]] then echo "$0: changed parameter $i: ${(q)parms_before[$i]}" \ " vs. ${(qP)i}" 1>&2 xit=1 fi done return $xit } Its purpose is to detect if any command (or function actually) has forgotten to declare a parameter or option as local. Eg. (intended,.but not actual output): % check-missing-locals somevar=1 check-missing-locals: set parameter somevar % check-missing-locals somevar=2 check-missing-locals: changed parameter somevar: 1 vs. 2 % check-missing-locals unset somevar check-missing-locals: unset parameter somevar % check-missing-locals setopt octal_zeroes check-missing-locals: changed option octalzeroes: off vs. on However, I get this: % check-missing-locals : check-missing-locals: changed option braceexpand: on vs. off check-missing-locals: unset parameter LANG check-missing-locals: unset parameter LC_ALL check-missing-locals: unset parameter LC_COLLATE check-missing-locals: unset parameter LC_CTYPE check-missing-locals: unset parameter LC_MESSAGES check-missing-locals: unset parameter LC_NUMERIC check-missing-locals: unset parameter LC_TIME What makes LANG, LC_* and the braceexpand option appear to be in different states at the beginning and the end of the function? Phil.