* Should zipping two empty arrays result in empty string? @ 2017-01-01 3:49 Eric Cook 2017-01-01 5:18 ` Kannan Varadhan 2017-01-01 20:24 ` Bart Schaefer 0 siblings, 2 replies; 6+ messages in thread From: Eric Cook @ 2017-01-01 3:49 UTC (permalink / raw) To: zsh-users The following code results in a single loop a=() b=(); for n in "${(@)a:^b}"; do typeset -p n; done typeset n='' My question is, would anyone expect that? or would the you expect nothing to expand, resulting in the loop not iterating? ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Should zipping two empty arrays result in empty string? 2017-01-01 3:49 Should zipping two empty arrays result in empty string? Eric Cook @ 2017-01-01 5:18 ` Kannan Varadhan 2017-01-01 8:50 ` Eric Cook 2017-01-01 20:24 ` Bart Schaefer 1 sibling, 1 reply; 6+ messages in thread From: Kannan Varadhan @ 2017-01-01 5:18 UTC (permalink / raw) To: Eric Cook, zsh-users Isn't this identical to % for i in "" ; do typeset -p i ; done which yields exactly one iteration, as I would expect? Kannan On 12/31/16 7:49 PM, Eric Cook wrote: > The following code results in a single loop > > a=() b=(); for n in "${(@)a:^b}"; do typeset -p n; done > typeset n='' > > My question is, would anyone expect that? or would the you expect > nothing to expand, resulting in the loop not iterating? ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Should zipping two empty arrays result in empty string? 2017-01-01 5:18 ` Kannan Varadhan @ 2017-01-01 8:50 ` Eric Cook 2017-01-01 9:17 ` Eric Cook 0 siblings, 1 reply; 6+ messages in thread From: Eric Cook @ 2017-01-01 8:50 UTC (permalink / raw) To: zsh-users On 01/01/2017 12:18 AM, Kannan Varadhan wrote: > Isn't this identical to > > % for i in "" ; do typeset -p i ; done > > which yields exactly one iteration, as I would expect? > That is indeed how it currently is, which is weird in my opinion. Because when you expand an empty array in any other instance, you don't get an argument/word; because there is none. I would expect it behave like: % for i in "${empty[@]}"; do typeset -p i; done Which won't iterate. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Should zipping two empty arrays result in empty string? 2017-01-01 8:50 ` Eric Cook @ 2017-01-01 9:17 ` Eric Cook 0 siblings, 0 replies; 6+ messages in thread From: Eric Cook @ 2017-01-01 9:17 UTC (permalink / raw) To: zsh-users On 01/01/2017 03:50 AM, Eric Cook wrote: > I would expect it behave like: > > % for i in "${empty[@]}"; do typeset -p i; done > > Which won't iterate. > i forgot the empty=(), which still results in not expanding a word that isn't in the array. python's zip function doesn't iterate: python -c 'for v in zip([],[]): print("loop")' nor ruby. ruby -e '[].zip([]).each { puts "loop" }' or perl perl -MList::Gen=zip -E 'say "loop" for zip [], [];' ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Should zipping two empty arrays result in empty string? 2017-01-01 3:49 Should zipping two empty arrays result in empty string? Eric Cook 2017-01-01 5:18 ` Kannan Varadhan @ 2017-01-01 20:24 ` Bart Schaefer 2017-01-01 20:27 ` [PATCH] zipping two empty arrays should not result in empty string Bart Schaefer 1 sibling, 1 reply; 6+ messages in thread From: Bart Schaefer @ 2017-01-01 20:24 UTC (permalink / raw) To: zsh-users On Dec 31, 10:49pm, Eric Cook wrote: } } The following code results in a single loop } } a=() b=(); for n in "${(@)a:^b}"; do typeset -p n; done } typeset n='' } } My question is, would anyone expect that? or would the you expect } nothing to expand, resulting in the loop not iterating? The zip operation is stepping on the internal state that records the semantics of (@)-inside-double-quotes, so it always behaves as if you did "${a[*]:^b}" instead. Patch to zsh-workers, assuming gmail doesn't get blocked again. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] zipping two empty arrays should not result in empty string 2017-01-01 20:24 ` Bart Schaefer @ 2017-01-01 20:27 ` Bart Schaefer 0 siblings, 0 replies; 6+ messages in thread From: Bart Schaefer @ 2017-01-01 20:27 UTC (permalink / raw) To: zsh-users On Jan 1, 12:24pm, Bart Schaefer wrote: } } The zip operation is stepping on the internal state that records the } semantics of (@)-inside-double-quotes, so it always behaves as if } you did "${a[*]:^b}" instead. Don't change isarr unless creating one from a scalar. diff --git a/Src/subst.c b/Src/subst.c index 64b4400..737a0a9 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -3066,7 +3066,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, if (sval) zip = hmkarray(sval); } - if (!isarr) aval = mkarray(val); + if (!isarr) { + aval = mkarray(val); + isarr = 1; + } if (zip) { char **out; int alen, ziplen, outlen, i = 0; @@ -3089,7 +3092,6 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, out[i*2] = NULL; aval = out; copied = 1; - isarr = 1; } } else { if (unset(UNSET)) { ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-01-01 20:57 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-01-01 3:49 Should zipping two empty arrays result in empty string? Eric Cook 2017-01-01 5:18 ` Kannan Varadhan 2017-01-01 8:50 ` Eric Cook 2017-01-01 9:17 ` Eric Cook 2017-01-01 20:24 ` Bart Schaefer 2017-01-01 20:27 ` [PATCH] zipping two empty arrays should not result in empty string 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).