about summary refs log tree commit diff
path: root/Doc/Zsh/expn.yo
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2014-07-31 19:39:26 +0200
committerMikael Magnusson <mikachu@gmail.com>2014-08-04 19:00:01 +0200
commitb8751cb9d71d9f8e0ff24c469a8011ff1a58b1a8 (patch)
treef4b233d6a58b488661cf2bd6f34b291f3728f006 /Doc/Zsh/expn.yo
parent1f396dbe25259d4279811c893cbf381d675ad97c (diff)
downloadzsh-b8751cb9d71d9f8e0ff24c469a8011ff1a58b1a8.tar.gz
zsh-b8751cb9d71d9f8e0ff24c469a8011ff1a58b1a8.tar.xz
zsh-b8751cb9d71d9f8e0ff24c469a8011ff1a58b1a8.zip
32949 (wip 32928, 32937): Add :^ syntax for zipping two arrays
Diffstat (limited to 'Doc/Zsh/expn.yo')
-rw-r--r--Doc/Zsh/expn.yo24
1 files changed, 24 insertions, 0 deletions
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 727901346..8394ffc4f 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -636,6 +636,30 @@ Similar to the preceding subsitution, but in the opposite sense,
 so that entries present in both the original substitution and as
 elements of var(arrayname) are retained and others removed.
 )
+xitem(tt(${)var(name)tt(:^)var(arrayname)tt(}))
+item(tt(${)var(name)tt(:^^)var(arrayname)tt(}))(
+Zips two arrays, such that the output array is twice as long as the
+shortest (longest for `tt(:^^)') of tt(name) and tt(arrayname), with
+the elements alternatingly being picked from them. For `tt(:^)', if one
+of the input arrays is longer, the output will stop when the end of the
+shorter array is reached.  Thus,
+
+example(a=(1 2 3 4); b=(a b); print ${a:^b})
+
+will output `tt(1 a 2 b)'.  For `tt(:^^)', then the input is repeated
+until all of the longer array has been used up and the above will output
+`tt(1 a 2 b 3 a 4 b)'.
+
+Either or both inputs may be a scalar, they will be treated as an array
+of length 1 with the scalar as the only element. If either array is empty,
+the other array is output with no extra elements inserted.
+
+Currently the following code will output `tt(a b)' and `tt(1)' as two separate
+elements, which can be unexpected. The second print provides a workaround which
+should continue to work if this is changed.
+
+example(a=(a b); b=(1 2); print -l "${a:^b}"; print -l "${${a:^b}}")
+)
 xitem(tt(${)var(name)tt(:)var(offset)tt(}))
 item(tt(${)var(name)tt(:)var(offset)tt(:)var(length)tt(}))(
 This syntax gives effects similar to parameter subscripting