3 ms·
I'm a bit young for perl, but I've had rather extensive experience with python at my last job, and it's my understanding that perl has a similar "global" soluti
by LordDragonfang 10y ago
I'm a bit young for perl, but I've had rather extensive experience with python at my last job, and it's my understanding that perl has a similar "global" solution with
for elem in collection:
and the `__iter__()` function. Correct?
- rurban 10y agono. perl5 can deal natively only with finite lists, not general iterators over infinite (lazy) lists. of course you can design an iterator over lazy lists, but you got no language support as with __iter__, other than using tie callbacks. only perl6 supports lazy lists and coroutines and yield. but iteration is only a trivial part of a design pattern. as the name says, a pattern is matching certain conditions, like number of arguments, types of arguments, context, ... and applies a specific solution to this pattern. perl5 and perl6 are not functional enough to provide this kind of pattern matching and functional dispatch. python and ruby neither. perl6 has multi-methods, but no proper matcher. Norvig explains a bit in http://norvig.com/design-patterns/design-patterns.pdf http://norvig.com/design-patterns/design-patterns.pdf, but in essence any strongly typed FP deals with that.
- falsedan 10y ago> but you got no language support as with __iter__, other than using tie callbacks. What are tie callbacks, if not (creaky) language support? Also the perl way would be to implement infinite streams, ala MJD's HOP[0]. [0]: http://hop.perl.plover.com/book/pdf/06InfiniteStreams.pdf http://hop.perl.plover.com/book/pdf/06InfiniteStreams.pdf