zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@u.genie.co.uk>
To: zsh-workers@sunsite.dk
Subject: Re: named references
Date: Wed, 27 Jun 2001 17:03:44 +0100	[thread overview]
Message-ID: <3B3A03E0.676FEDFC@u.genie.co.uk> (raw)
In-Reply-To: <000201c0fd36$673064e0$21c9ca95@mow.siemens.ru>

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


  reply	other threads:[~2001-06-27 16:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-24 11:34 Oliver Kiddle
2001-06-24 18:28 ` Bart Schaefer
2001-06-27 19:01   ` Oliver Kiddle
2001-06-28  8:07     ` Andrej Borsenkow
2001-06-28  8:30       ` Bart Schaefer
2001-06-28  9:39     ` Peter Stephenson
2001-06-30  7:56       ` Bart Schaefer
2001-07-02  9:31         ` Peter Stephenson
2001-06-30  7:37     ` Bart Schaefer
2001-07-09 19:43       ` Oliver Kiddle
2001-06-25  5:19 ` Andrej Borsenkow
2001-06-27 16:03   ` Oliver Kiddle [this message]
2001-06-27 16:50     ` Peter Stephenson
2001-06-27 19:18       ` Oliver Kiddle
2001-06-30  8:09         ` Bart Schaefer
2001-06-27 17:14     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3B3A03E0.676FEDFC@u.genie.co.uk \
    --to=opk@u.genie.co.uk \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).