标签云

微信群

扫码加入我们

WeChat QR Code


Haskell's zip is not what you are looking for: it returns a list of corresponding pairs, not a list of interleaved elements.

2018年09月25日37分39秒

You're right; Haskell lists contains elements if a single type. I wasn't thinking when I referred to Haskell here.

2018年09月25日37分39秒

Often when one thinks they want a zip, it's to create a hash from two lists. In that case better to use a hash slice. hash{keys} = values. If that's not the case here, then sorry for the noise.

2018年09月25日37分39秒

wow, that's clear and concise!!!

2018年09月25日37分39秒

+++1 smart & short

1970年01月01日00分01秒

my mind is blown!

2018年09月25日37分39秒

I don't know how I managed to overlook that module - thanks!

2018年09月26日37分39秒

What are those escaped at-signs?

2018年09月26日37分39秒

Prototypes, saying it takes two to 32 array parameters and the sub will implicitly receive them as arrayrefs.

2018年09月26日37分39秒

My eyes bleed! Isn't there some shortcut like \{32} or something similiar?

2018年09月25日37分39秒

Roberto, no but that's simply a prototype hack, your eyes are bleeding for all the wrong reason.

2018年09月25日37分39秒

This has problems for unequally-sized arrays.

2018年09月26日37分39秒

briandfoy your comments help, but you know what you forgot to do? point out which one does work for unequally-sized arrays. (I'm shopping for one that needs to do this)

2018年09月26日37分39秒

I didn't forget. That problem depends on what you want to do with the remaining elements. You should ask a different question and specify your constraints.

2018年09月25日37分39秒

Really nice solution. It takes long to understand it for me.

2018年09月25日37分39秒

This has problems for unequally-sized arrays.

2018年09月26日37分39秒

Using bit shifts might be faster in C but is just unnecessary obfuscation in Perl. Better written like so: _[ map { $_, $_ + _/2 } 0 .. ( _/2 - 1 ) ] Shorter, too.

2018年09月26日37分39秒

It isn't an issue for the question here, but my zip was designed to work for odd numbers of elements too.

2018年09月25日37分39秒

Nice solution, I should probably have expressed my preference for not modifying the two input-lists :-)

2018年09月25日37分39秒