From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26872 invoked from network); 20 Dec 2004 12:16:19 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 20 Dec 2004 12:16:19 -0000 Received: (qmail 86499 invoked from network); 20 Dec 2004 12:16:13 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 20 Dec 2004 12:16:13 -0000 Received: (qmail 26545 invoked by alias); 20 Dec 2004 12:16:05 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8305 Received: (qmail 26533 invoked from network); 20 Dec 2004 12:16:04 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 20 Dec 2004 12:16:04 -0000 Received: (qmail 84798 invoked from network); 20 Dec 2004 12:15:05 -0000 Received: from mxfep02.bredband.com (195.54.107.73) by a.mx.sunsite.dk with SMTP; 20 Dec 2004 12:15:04 -0000 Received: from puritan.pcp.ath.cx ([213.112.43.197] [213.112.43.197]) by mxfep02.bredband.com with ESMTP id <20041220121503.CNAQ6820.mxfep02.bredband.com@puritan.pcp.ath.cx> for ; Mon, 20 Dec 2004 13:15:03 +0100 Received: by puritan.pcp.ath.cx (Postfix, from userid 1000) id 832C3AE044; Mon, 20 Dec 2004 13:15:04 +0100 (CET) Date: Mon, 20 Dec 2004 13:15:04 +0100 From: Nikolai Weibull To: zsh-users@sunsite.dk Subject: Re: local/typeset stupidity Message-ID: <20041220121504.GB9720@puritan.pcp.ath.cx> Mail-Followup-To: zsh-users@sunsite.dk References: <20041220112025.GA9720@puritan.pcp.ath.cx> <200412201151.iBKBp14U018627@news01.csr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200412201151.iBKBp14U018627@news01.csr.com> User-Agent: Mutt/1.5.6i X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: * X-Spam-Status: No, hits=1.5 required=6.0 tests=RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 1.5 * Peter Stephenson [Dec 20, 2004 13:00]: > > func () { local s="..." } > > > > then I don't expect zsh to respond with > > > > func:local:1: not valid in this context: 100 > > > > right? > There's something you're not telling us. With the default zsh options > the syntax you show is guaranteed to work. My guess is something is > causing what you show in "..." to be split into words. Is there a > "$@" inside it? For example, > func() { local s="$@" } func foo 100 Argh, man, I need to get used to hom $(...) works. It looks like one element, but its of course split in that position. > s="..." > is special syntax; it's recognised as a scalar assignment, so > wordsplitting is implicitly turned off. This differs from "local" > which has the semantics of a normal builtin, almost (actually, there's > special behaviour of ~'s and ='s at the start of the value). > This is rather nasty. People often expect assignments after "local" > etc. to be the same as assignments on their own, but that syntax > conflicts with the way the arguments of builtins, and any other > commands, are handled. There's no simple answer, but retaining > builtin syntax is at least predictable and stops the already > horrendous code for local variables from becoming any worse. Any way > round is a kludge of some sort. This is what fooled me, yes. > > Even with > > > > setopt typesetsilent # (how can't this be the default?) > typesetsilent works around a different problem: > func() { local s; local s; } func > outputs > s='' > unless the option is turned on. This came from the very early days of > zsh. It was mostly useful for examining the state of variables that > already exist interactively; it's not obvious you would use it in a > function. It's annoying this is the default behaviour. There may be > a better way of suppressing the output in functions, but I'm not sure > whose functions it would break. Personally I'd be quite happy to have > the effect of typesetsilent enforced inside functions. A compromise > would be to keep the non-silent behaviour only for "typeset" itself. Yes, definitely. It's weird where the language has dynamic binding, yet "complains" about things like this. Thanks for your help, nikolai -- ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka ::: ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden ::: ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 ::: main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}