Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

${(P)${foo}} (Re: Associative array ordering)



On Feb 2,  5:58pm, Sven Wischnowsky wrote:
} Subject: Re:  Associative array ordering and selective unset (Re: Example 
}
} I wrote:
} 
} > Maybe yet another flag? E.g.: `P' makes the thing after the
} > flags be used as the name of a parameter. So `${(P)foo}' is the same
} > as `$foo', but `${(P)${foo}}' will take the value of `foo' as the name 
} > of a parameter and work on it.
} 
} The patch below does this (it was quite easy).

Well, you got to that before I got around to responding to that particular
tidbit.

The other day someone asked about ksh namerefs in zsh, and I said that with
${(e)...} you didn't really need them.  Here's a case where they would have
been exactly what the doctor ordered; in an appropriate muddle of ksh and
zsh syntax,

	nameref ref=$arg[1]
	echo ${(t)!ref}

which is a whole lot easier on the eyes, it must be admitted.

} With it you can do
} things like the above or `${(P)+${foo}}' to see if the parameter whose 
} name is stored in `foo' is set.

There are actually several ways we can go from here.

We can keep Sven's syntax as is.

We can modify Sven's syntax so that ${(P)foo} is the same as ${(P)${foo}},
and make ${!foo} a synonym for it in ksh compatibility mode.  This is
almost like ksh namerefs except that they don't get their own namespace.

We can make ${!foo} a synonym for ${(P)${foo}} (either in ksh mode or all
the time), leaving ${(P)foo} alone.  I'm not too thrilled about this one.

We can add another hash table to be the nameref namespace, implement the
nameref and `typeset -n' builtins, and make ${(P)foo} [or another letter]
and ${!foo} synonyms where `foo' must be a nameref.  That would deprecate
${(P)${foo}}.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author