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

bug: nested for loop body is executed once!



Hi,

I just spot a following bug on Big Sur zsh 5.8 (x86_64-apple-darwin20.0)

$ K="1 2 3"
$ for i in $(for j in $K; do echo "ddd/$j" ; done) ; do echo  "$i" ; done
ddd/1
2
3

I would expect following output
ddd/1
ddd/2
ddd/3
 
this breaks referential transparency - sorry for FP buzzwords ;)
because 

$ for i in $(for j in $(echo 1 2 3); do echo "ddd/$j" ; done) ; do echo  "$i" ; done

produce expected output:
ddd/1
ddd/2
ddd/3


I don't know if this is a feature due to some legacy optimizations.
I mostly use BASH and this behavior differs from BASH.
BASH behaves exactly as I expect.

P.S.
Wow! Are you still using just a mailing list for bug tracking?!
I hope my HTML email will be rendered correctly ;)

--

Best regards,
Daniil Iaitskov


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