From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-users@zsh.org
Subject: Re: r/w access to calling function's $@
Date: Tue, 13 May 2014 17:58:56 +0100 [thread overview]
Message-ID: <20140513175856.16a875b2@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20140513164206.GD1629@isis.sigpipe.cz>
On Tue, 13 May 2014 18:42:06 +0200
Roman Neuhauser <neuhauser@sigpipe.cz> wrote:
> > Failing that you have to do something nasty like using "eval" to avoid
> > exposing the point where it gets transferred to the current argument
> > set.
>
> not sure what exactly you have on mind here, could you give me a sketch?
Use "reply" as alluded to by Bart but disguise the update to argv. I
can't think of a good reason to do this rather than just living with the
limitation and manipulating $reply explicitly. Also, this method makes
it hard to pass *in* arguments.
my_function_that_does_the_real_stuff()
{
typeset -g reply # in case the caller didn't localise it
reply=(my reply value)
}
my_disguise='
my_function_that_does_the_real_stuff
argv=("${reply[@]}")
'
# Call a function, disguising the fact that it updates $argv.
eval $my_disguise
Bart's idea of an EXIT trap is a bit neater. For functions the EXIT
trap explicitly gets called in the caller's scope.
% print $*
% pass_back() { trap 'argv=(my results)' EXIT; }
% pass_back
% print $*
my results
There's still what amounts to an eval in there, however.
pws
next prev parent reply other threads:[~2014-05-13 16:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-13 16:01 Roman Neuhauser
2014-05-13 16:13 ` Peter Stephenson
2014-05-13 16:42 ` Roman Neuhauser
2014-05-13 16:58 ` Peter Stephenson [this message]
2014-05-13 16:43 ` 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=20140513175856.16a875b2@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-users@zsh.org \
/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).