From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4216 invoked from network); 27 Jun 2001 16:03:54 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 27 Jun 2001 16:03:54 -0000 Received: (qmail 14634 invoked by alias); 27 Jun 2001 16:03:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 15142 Received: (qmail 14620 invoked from network); 27 Jun 2001 16:03:03 -0000 Sender: kiddleo Message-ID: <3B3A03E0.676FEDFC@u.genie.co.uk> Date: Wed, 27 Jun 2001 17:03:44 +0100 From: Oliver Kiddle X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.15 i686) X-Accept-Language: en MIME-Version: 1.0 To: zsh-workers@sunsite.dk Subject: Re: named references References: <000201c0fd36$673064e0$21c9ca95@mow.siemens.ru> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Andrej wrote: > Apart from obvious "it was fun to implement" - can somebody give an example > for use of nameref? I mean, real examples, where other means are > impossible/have disatvantage over nameref. To be honest, I've tried to > imagine one and failed (ksh93 compatibility issue aside). Any situation where you want a function to return a value and the exit code is not sufficient. This can currently be done with an eval but it is messy, especially with associative arrays. The nameref can be used like any normal variable so you end up with more readable code: at the moment, you would need to define a local for the return value, and before returning, assign it across with eval: typeset -A $1 eval $1'=( ${(kv)ret} )' it is much more readable if the function just starts with: nameref ret="$1" If we ever implement other more complex parameter types (such as something like ksh93 namespaces), it would be even more useful because the eval code for them could be even more messy. Also, unlike eval, namerefs can reference variables at a higher local level so in the above `ret' could be passed as $1 safely. I'd also expect that if we ever implement anything like dtksh/tksh as a module, more scripts would be written which would use namerefs. Namerefs could also be useful for simple cases where an alternate name is wanted, maybe to allow a different language such as we have already done with ZLS_COLOURS/ZLS_COLORS or for things like prompt. You even suggested some sort of parameter aliasing in 12830. Does anyone else have an opinion on whether namerefs would be a useful addition? I'd prefer this to be decided now rather than after I spend more time on them. Oliver