* cross-product array function?
@ 1998-02-03 19:08 Sweth Chandramouli
1998-02-03 19:26 ` Andrew Main
0 siblings, 1 reply; 8+ messages in thread
From: Sweth Chandramouli @ 1998-02-03 19:08 UTC (permalink / raw)
To: ZSH Users
is there a function in zsh to take two arrays/lists, and create a new
one that is their cross-product? in es (extensible shell), i could do
foo="first second third";
bar="word person base";
echo foo^bar;
and the output would be the following list:
"firstword secondword thirdword firstperson secondperson thirdperson firstbase
secondbase thirdbase"
is there some similar function in zsh?
tia,
sweth.
--
"Countin' on a remedy I've counted on before
Goin' with a cure that's never failed me
What you call the disease
I call the remedy" -- The Mighty Mighty Bosstones
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: cross-product array function?
1998-02-03 19:08 cross-product array function? Sweth Chandramouli
@ 1998-02-03 19:26 ` Andrew Main
1998-02-03 19:51 ` Sweth Chandramouli
1998-02-03 20:59 ` Nate Johnston
0 siblings, 2 replies; 8+ messages in thread
From: Andrew Main @ 1998-02-03 19:26 UTC (permalink / raw)
To: Sweth Chandramouli; +Cc: zsh-users
Sweth Chandramouli wrote:
> is there a function in zsh to take two arrays/lists, and create a new
>one that is their cross-product? in es (extensible shell), i could do
>
>foo="first second third";
>bar="word person base";
>echo foo^bar;
foo=(first second third)
bar=(word person base)
echo $^foo$^bar
-zefram
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: cross-product array function?
1998-02-03 19:26 ` Andrew Main
@ 1998-02-03 19:51 ` Sweth Chandramouli
1998-02-03 20:00 ` Andrew Main
1998-02-03 20:59 ` Nate Johnston
1 sibling, 1 reply; 8+ messages in thread
From: Sweth Chandramouli @ 1998-02-03 19:51 UTC (permalink / raw)
To: zsh-users
On Tue, Feb 03, 1998 at 07:26:18PM +0000, Andrew Main wrote:
> foo=(first second third)
> bar=(word person base)
> echo $^foo$^bar
>
> -zefram
which part of the manpage would that be in? i couldn't find anything
when searching for $^.
tia,
sweth.
--
"Countin' on a remedy I've counted on before
Goin' with a cure that's never failed me
What you call the disease
I call the remedy" -- The Mighty Mighty Bosstones
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: cross-product array function?
1998-02-03 19:51 ` Sweth Chandramouli
@ 1998-02-03 20:00 ` Andrew Main
0 siblings, 0 replies; 8+ messages in thread
From: Andrew Main @ 1998-02-03 20:00 UTC (permalink / raw)
To: Sweth Chandramouli; +Cc: zsh-users
Sweth Chandramouli wrote:
> which part of the manpage would that be in? i couldn't find anything
>when searching for $^.
zshexpn(1), the section "Parameter Expansion". Search for "${^".
-zefram
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: cross-product array function?
1998-02-03 19:26 ` Andrew Main
1998-02-03 19:51 ` Sweth Chandramouli
@ 1998-02-03 20:59 ` Nate Johnston
1998-02-03 22:39 ` Sweth Chandramouli
` (2 more replies)
1 sibling, 3 replies; 8+ messages in thread
From: Nate Johnston @ 1998-02-03 20:59 UTC (permalink / raw)
To: Andrew Main; +Cc: zsh-users
On Tue, 3 Feb 1998, Andrew Main wrote:
#foo=(first second third)
#bar=(word person base)
#echo $^foo$^bar
I attempted this, and I had an odd result on the first element of the
first array. Is this broken in the version I use?
natej:~> ONE=(1 2 3)
natej:~> TWO=(A B C)
natej:~> echo $^ONE$^TWO
1C 2A 2B 2C 3A 3B 3C
zsh: 3.0.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: cross-product array function?
1998-02-03 20:59 ` Nate Johnston
@ 1998-02-03 22:39 ` Sweth Chandramouli
1998-02-03 22:45 ` Thomas Köhler
1998-02-04 9:29 ` Andrew Main
2 siblings, 0 replies; 8+ messages in thread
From: Sweth Chandramouli @ 1998-02-03 22:39 UTC (permalink / raw)
To: zsh-users
On Tue, Feb 03, 1998 at 03:59:44PM -0500, Nate Johnston wrote:
> On Tue, 3 Feb 1998, Andrew Main wrote:
>
> #foo=(first second third)
> #bar=(word person base)
> #echo $^foo$^bar
>
> I attempted this, and I had an odd result on the first element of the
> first array. Is this broken in the version I use?
>
> natej:~> ONE=(1 2 3)
> natej:~> TWO=(A B C)
> natej:~> echo $^ONE$^TWO
> 1C 2A 2B 2C 3A 3B 3C
>
> zsh: 3.0.0
i get this behaviour too, with 3.1.2.
even stranger is what happens with more than two items variables being
expanded; the behaviour is the same if i use the $^ shortcut. i was expecting
the output to be
1AZ 1BX 1BY 1BZ 1CX 1CY 1CZ 2AX 2AY 2AZ 2BX 2BY 2BZ 2CX 2CY 2CZ 3AX 3AY 3AZ 3BX
3BY 3BZ 3CX 3CY 3CZ
, where all of the elements of the first expansion were lost but the
last one, or perhaps
1CZ 2AX 2AY 2AZ 2BX 2BY 2BZ 2CX 2CY 2CZ 3AX 3AY 3AZ 3BX 3BY 3BZ 3CX 3CY 3CZ
(depending on if the expansion were recursive or not). if everything
were working okay, i would have expected
1AX 1AY 1AZ 1BX 1BY 1BZ 1CX 1CY 1CZ 2AX 2AY 2AZ 2BX 2BY 2BZ 2CX 2CY 2CZ 3AX 3AY
3AZ 3BX 3BY 3BZ 3CX 3CY 3CZ
but instead, there is this very strange output:
$ foo=(1 2 3)
$ bar=(A B C)
$ mug=(X Y Z)
$ setopt rcexpandparam
$ echo ${foo}${bar}${mug}
1CZ 2AZ 2BX 2BY 2BZ 2CX 2CY 2CZ 3AZ 3BX 3BY 3BZ 3CX 3CY 3CZ
is this a bug? feature? gross network error somewhere between the chair
and the keyboard?
--
"Countin' on a remedy I've counted on before
Goin' with a cure that's never failed me
What you call the disease
I call the remedy" -- The Mighty Mighty Bosstones
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: cross-product array function?
1998-02-03 20:59 ` Nate Johnston
1998-02-03 22:39 ` Sweth Chandramouli
@ 1998-02-03 22:45 ` Thomas Köhler
1998-02-04 9:29 ` Andrew Main
2 siblings, 0 replies; 8+ messages in thread
From: Thomas Köhler @ 1998-02-03 22:45 UTC (permalink / raw)
To: zsh-users
On Feb 3, Nate Johnston wrote
> On Tue, 3 Feb 1998, Andrew Main wrote:
>
> #foo=(first second third)
> #bar=(word person base)
> #echo $^foo$^bar
>
> I attempted this, and I had an odd result on the first element of the
> first array. Is this broken in the version I use?
>
> natej:~> ONE=(1 2 3)
> natej:~> TWO=(A B C)
> natej:~> echo $^ONE$^TWO
> 1C 2A 2B 2C 3A 3B 3C
>
> zsh: 3.0.0
Same here, using zsh-3.1.2 - a really weird thing...
--
-- Thomas Köhler Email: jean-luc@picard.franken.de
<>< jean-luc@mayn.de
IRC: jeanluc Channels: #star_trek #linuxger #ixthys #knf
WWW: http://home.pages.de/~jeanluc/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: cross-product array function?
1998-02-03 20:59 ` Nate Johnston
1998-02-03 22:39 ` Sweth Chandramouli
1998-02-03 22:45 ` Thomas Köhler
@ 1998-02-04 9:29 ` Andrew Main
2 siblings, 0 replies; 8+ messages in thread
From: Andrew Main @ 1998-02-04 9:29 UTC (permalink / raw)
To: Nate Johnston; +Cc: zefram, zsh-users
Nate Johnston wrote:
>I attempted this, and I had an odd result on the first element of the
>first array. Is this broken in the version I use?
Ah yes, I should have mentioned that. It's broken up to 3.1.2. There
were a couple of big patches to fix it (and to make $^foo act exactly like
brace expansion), which got into 3.1.2-zefram3. So, basically, FITNR.
-zefram
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1998-02-04 9:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-03 19:08 cross-product array function? Sweth Chandramouli
1998-02-03 19:26 ` Andrew Main
1998-02-03 19:51 ` Sweth Chandramouli
1998-02-03 20:00 ` Andrew Main
1998-02-03 20:59 ` Nate Johnston
1998-02-03 22:39 ` Sweth Chandramouli
1998-02-03 22:45 ` Thomas Köhler
1998-02-04 9:29 ` Andrew Main
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).