From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27243 invoked by alias); 27 Jun 2015 23:08:10 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35645 Received: (qmail 1423 invoked from network); 27 Jun 2015 23:08:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=s03hhc1A29Ztx8qVzKeBxqygmUxFbDQruzK7tMYQ+Qk=; b=gSl+Foe/7GCXM8/HFjLPWospsMnQ3HbRrlJ7hnBX0HJCEx/JKYmQfE5kjCfXGLDxdQ 2lIWCPCLwMq/T3OGLoiXZwOCUoqXdEGOqH5frURvKuSZrpkT8BTKPYsZmhyxWcDmS1WA /72pZ9+aDxoDUtQJJ7DsJkdxdemy2SDUWTXAXmx9hb2qhuJlMp4apxQjbxvQUNrYDikO oQ3MI2ZVh2Ctbt7Ka57b2ky4+eP1E9JCEvQ6fg1+yJIB7qsE9Vj10/84oR3YD9sZ3WDI 9iB+aw8o8flPOOm5cN/CD5v05TIog0Lsh+dj46Z8nFkqHbP0KeCqQz5l83lMu8rMiY0b 0cSA== X-Gm-Message-State: ALoCoQn7P0IGV5aWHTtWkFwiCW6Jv+uOzmuzGoZ6Wslqk5iImLbs9v2JkJ+dAZlVCH+G4GE7KvdX X-Received: by 10.60.92.131 with SMTP id cm3mr7288782oeb.23.1435446485805; Sat, 27 Jun 2015 16:08:05 -0700 (PDT) From: Bart Schaefer Message-Id: <150627160802.ZM7033@torch.brasslantern.com> Date: Sat, 27 Jun 2015 16:08:02 -0700 In-Reply-To: <29780.1435441543@thecus.kiddle.eu> Comments: In reply to Oliver Kiddle "Re: Obtaining the names of all local variables" (Jun 27, 11:45pm) References: <150625084618.ZM20163@torch.brasslantern.com> <29780.1435441543@thecus.kiddle.eu> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Obtaining the names of all local variables MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jun 27, 11:45pm, Oliver Kiddle wrote: } Subject: Re: Obtaining the names of all local variables } } Bart wrote: } > This got me thinking, wouldn't it be helpful if zsh/parameter had an array } > $locals that holds the names of all the local parameters? Then you could } > } > needs_private_scope() { local -h $locals; ... } } } I'm not sure I understand how that would achieve a private scope. A few weeks ago someone asked for what amounts to lexical scoping of local variables instead of dynamic scoping. There's no way to achieve that completely, but if you can hide all the variables that your caller has made local, you get at least part of the way; you are then guaranteed not to accidentally poke something into the caller's scope. } -h is only applicable to special parameters. Right, but if $locals contains a mix of non-special and special, you (might) need the -h there. The real point is to make the non-specials local as well, which this ... } local -h ${(k)parameters[(R)*-special]} ... does not do, and besides that also makes the global specials local, which is NOT the point. } Or you could mark every parameter local. That also hides the globals, which again is not the desired effect. If there were a version of "typeset -g" that meant "expose the listed top-level global variables, regardless of intervening dynamic scopes" that would actually be a better starting point, but I think that's a lot more difficult to achieve. Maybe I'm wrong.