zsh-workers
 help / color / mirror / code / Atom feed
* use 'P' parameter expansion flag with array?
@ 2009-06-30  3:20 Greg Klanderman
  2009-06-30  8:43 ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Greg Klanderman @ 2009-06-30  3:20 UTC (permalink / raw)
  To: Zsh list


If the 'P' parameter expansion flag is applied to an array parameter,
should it be applied to each of the elements?  Seems like it should,
but it doesn't seem to be:


[~] greg@lwm| zsh -f
lwm% 
lwm% echo $ZSH_VERSION
4.3.10-dev-1
lwm% foo=(bar baz)
lwm% bar=10
lwm% baz=35
lwm% echo ${(P)foo}
10
lwm% echo ${(P@)foo}
10
lwm% echo ${(P)foo[@]}
10
lwm% 


thanks,
Greg


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

* Re: use 'P' parameter expansion flag with array?
  2009-06-30  3:20 use 'P' parameter expansion flag with array? Greg Klanderman
@ 2009-06-30  8:43 ` Peter Stephenson
  2009-06-30 15:08   ` Greg Klanderman
  2009-07-05 19:56   ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 2009-06-30  8:43 UTC (permalink / raw)
  To: Zsh list

Greg Klanderman wrote:
> If the 'P' parameter expansion flag is applied to an array parameter,
> should it be applied to each of the elements?

It does seem logical, but the code is obscure and it's not clear whether
this was intended or not---it probably fell through the cracks.  I don't
think the flag was completely thought through in other ways I've noticed
in the past, though I've forgotten what they are for the time being.
paramsubst() is full of my "one day someone should spend a year tidying
this up" comments.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


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

* Re: use 'P' parameter expansion flag with array?
  2009-06-30  8:43 ` Peter Stephenson
@ 2009-06-30 15:08   ` Greg Klanderman
  2009-06-30 15:19     ` Mikael Magnusson
  2009-07-05 19:56   ` Bart Schaefer
  1 sibling, 1 reply; 6+ messages in thread
From: Greg Klanderman @ 2009-06-30 15:08 UTC (permalink / raw)
  To: zsh-workers


> It does seem logical, but the code is obscure and it's not clear whether
> this was intended or not---it probably fell through the cracks.

Thank you Peter, I'll just use a loop then..

> paramsubst() is full of my "one day someone should spend a year tidying
> this up" comments.

Yeah I enjoyed reading a number of those last night after sending
that question  :-)

So if I have an array and want to append a string to each of the
elements, then join with colon, is there a better way than this:

lwm% a=(x y z)
lwm% echo ${(j.:.)${(@)a/%/foo}}
xfoo:yfoo:zfoo

I was trying to do something using '^' but it doesn't seem to work;

lwm% echo ${(@)^a}foo
xfoo yfoo zfoo

does what I expect, but:

lwm% echo ${(j.:.)${(@)^a}foo}
zsh: bad substitution

does not.

thanks,
Greg


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

* Re: use 'P' parameter expansion flag with array?
  2009-06-30 15:08   ` Greg Klanderman
@ 2009-06-30 15:19     ` Mikael Magnusson
  2009-06-30 15:51       ` Greg Klanderman
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2009-06-30 15:19 UTC (permalink / raw)
  To: zsh-workers

2009/6/30 Greg Klanderman <gak@klanderman.net>:
>
>> It does seem logical, but the code is obscure and it's not clear whether
>> this was intended or not---it probably fell through the cracks.
>
> Thank you Peter, I'll just use a loop then..
>
>> paramsubst() is full of my "one day someone should spend a year tidying
>> this up" comments.
>
> Yeah I enjoyed reading a number of those last night after sending
> that question  :-)
>
> So if I have an array and want to append a string to each of the
> elements, then join with colon, is there a better way than this:
>
> lwm% a=(x y z)
> lwm% echo ${(j.:.)${(@)a/%/foo}}
> xfoo:yfoo:zfoo
>
> I was trying to do something using '^' but it doesn't seem to work;
>
> lwm% echo ${(@)^a}foo
> xfoo yfoo zfoo
>
> does what I expect, but:
>
> lwm% echo ${(j.:.)${(@)^a}foo}
> zsh: bad substitution
>
> does not.

echo ${(j.:.):-${(@)^a}foo}
will work fine, the simplest case of the error is this, i think:
% echo ${${}foo}
zsh: bad substitution
% echo ${:-${}foo}
foo

-- 
Mikael Magnusson


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

* Re: use 'P' parameter expansion flag with array?
  2009-06-30 15:19     ` Mikael Magnusson
@ 2009-06-30 15:51       ` Greg Klanderman
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Klanderman @ 2009-06-30 15:51 UTC (permalink / raw)
  To: zsh-workers

>>>>> Mikael Magnusson <mikachu@gmail.com> writes:

> echo ${(j.:.):-${(@)^a}foo}

Thank you Mikael!  I really need a zsh cheat-sheet..

greg


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

* Re: use 'P' parameter expansion flag with array?
  2009-06-30  8:43 ` Peter Stephenson
  2009-06-30 15:08   ` Greg Klanderman
@ 2009-07-05 19:56   ` Bart Schaefer
  1 sibling, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2009-07-05 19:56 UTC (permalink / raw)
  To: Zsh list

On Jun 30,  9:43am, Peter Stephenson wrote:
}
} Greg Klanderman wrote:
} > If the 'P' parameter expansion flag is applied to an array parameter,
} > should it be applied to each of the elements?
} 
} It does seem logical, but the code is obscure and it's not clear whether
} this was intended or not---it probably fell through the cracks.

The (P) flag was supposed to create an approximate equivalent of ksh
"nameref" parameters.  Because of the way array expansion operates in
ksh and similar shells, extending (P) to an automatic "map" over an
array wasn't considered.


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

end of thread, other threads:[~2009-07-05 19:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-30  3:20 use 'P' parameter expansion flag with array? Greg Klanderman
2009-06-30  8:43 ` Peter Stephenson
2009-06-30 15:08   ` Greg Klanderman
2009-06-30 15:19     ` Mikael Magnusson
2009-06-30 15:51       ` Greg Klanderman
2009-07-05 19:56   ` 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).