From: gabriele renzi Date: 2004-04-07T15:09:17+09:00 Subject: Re: deciding between ruby and python il Wed, 07 Apr 2004 05:35:39 GMT, dagbrown@LART.ca (Dave Brown) ha scritto:: >In article , >gabriele renzi wrote: >: In ruby you're forced to build a huge array any time you use zip, whle >: in python you can delay the creation of the yielded pair till they're >: actually useful. > >Nope. yep just look at you own output. Now, if you're not convinced try this: >> def infinity >> end => nil >> require 'mathn' => true >> p=Prime.new => # >> for i in [1,2,3].zip(p) >> p i >> end TypeError: cannot convert Prime into Array from (irb):5:in `zip' from (irb):5 >> p.kind_of?Enumerable => true guess why you can't use a prime? because you can't pause the yielding. You're forced to use the whole number of Prime number that are actually.. infinite. So, you discover that you can't zip it cause zip calls to_ary. lazy generators allows you to use just one element at a time, so zip can be used for any kind of enumerable. > >It's those blocks and yield again! Aren't they great? Stick a block >after a zip and instead of building a great big array, it yields pairs >for you to do what you want with. yes, after it constructed one big array:)