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

Nofork ${{var}...} edge cases



Just seeking opinions:

Should ${{} true} (empty variable name) result in "bad substitution"?
Otherwise it's all side-effects, because nothing will be substituted.
The prior ${|| true} form was a parse error.

Should ${{var}} be a "bad substitution", or print a warning about an
empty command?  Otherwise it just substitutes $var.

What about ${{var};} or ${{var}{}} etc.?

Given:
% REPLY=123
Currently this works:
% print ${{REPLY} REPLY=abc}
abc
%
But the following does not substitute "b":
% print ${{REPLY[2]} REPLY=abc}
2
%

That's because REPLY is implicitly local to the substitution but
REPLY[2] becomes linked to the caller's $REPLY.  (This is a problem
with |REPLY[2]| as well, not new with the braces.)  With any other
name than REPLY, the subscript works as expected.  How much effort is
it worth putting into fixing this?  I would expect it more typical to
do:
% print ${${| REPLY=abc}[2]}
b
%

Or we could declare ${{REPLY}...} as NOT synonymous with ${|...} and
localize REPLY only in the latter of those.  That might actually make
more sense.

In an earlier thread, Oliver asked:
> Given that the ${|var| ... } form appears to create a function-like
> scope, should var perhaps be auto-declared local for that scope and the
> local value be substituted?

Among the reasons I listed for not doing this, I forgot to mention
that subscripts are allowed and you can't localize a subscripted
parameter.

I'd like to resolve these before I update the Doc.




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