zsh-workers
 help / color / mirror / code / Atom feed
* nameref and argv
@ 2023-11-21 10:27 Stephane Chazelas
  2023-11-21 18:35 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Stephane Chazelas @ 2023-11-21 10:27 UTC (permalink / raw)
  To: zsh-workers

$ ./Src/zsh -c 'f() { nameref a=argv; g x y; }; g() { echo $a; }; f a b 
c'
x y

I was expecting to see "a b c" there like in:

$ ./Src/zsh -c 'f() { local args=(a b c); nameref a=args; g}; g() { 
local args=(x y); echo $a; }; f'
a b c

-- 
Stephane


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: nameref and argv
  2023-11-21 10:27 nameref and argv Stephane Chazelas
@ 2023-11-21 18:35 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2023-11-21 18:35 UTC (permalink / raw)
  To: Stephane Chazelas; +Cc: zsh-workers

On Tue, Nov 21, 2023 at 2:27 AM Stephane Chazelas <stephane@chazelas.org> wrote:
>
> $ ./Src/zsh -c 'f() { nameref a=argv; g x y; }; g() { echo $a; }; f a b c'
> x y
>
> I was expecting to see "a b c" there

Although argv acts like a local, it's actually a global special, so
you always get the special behavior even when accessing through a
nameref.

I thought I'd mentioned this somewhere in the doc but perhaps not.

Underneath, argv ends up being a pointer into the C stack, so there's
no way to get a reference to it from a called function up to the
caller.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-21 18:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21 10:27 nameref and argv Stephane Chazelas
2023-11-21 18:35 ` Bart Schaefer

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).