Re:Let's Write an LLVM Specializer for Python
by halflings on Thursday January 22, 2015 @09:42AM
(#8929330)
The example you gave works perfectly in Python 2.7 (would also be a generator, and you're not using map filter or else); but I agree: those should've been generators from day 1, especially zip and enumerate since they make more elegant code but often come with a performance overhead in Python 2.7
[ Parent
| on HN ]
Re:Let's Write an LLVM Specializer for Python
by maxerickson on Thursday January 22, 2015 @09:58AM
(#8929424)
Python 2 enumerate returns an 'enumerate' object that is more or less a light weight wrapper of the sequence that was passed in.
Generators provide a convenient syntax to implement that sort of object.
Re:Let's Write an LLVM Specializer for Python
by exDM69 on Thursday January 22, 2015 @10:06AM
(#8929483)
D'oh. I put in a map(), that returns a list.
Re:Let's Write an LLVM Specializer for Python
by danohuiginn on Thursday January 22, 2015 @09:56AM
(#8929410)
Turning them into generators would have broken a lot of existing code, though, so it's reasonable to leave them until a major version change.
Rather, these are the kind of small, obviously-useful changes that should have come immediately in 3.0, giving people some encouragement to switch.
Re:Let's Write an LLVM Specializer for Python
by exDM69 on Thursday January 22, 2015 @10:06AM
(#8929487)
Most of the breaking changes (including making map, zip, filter, etc lazy) were done in Python 3.0.
Re:Let's Write an LLVM Specializer for Python
by exDM69 on Thursday January 22, 2015 @09:52AM
(#8929386)
Ah, you're absolutely right. for line in open(filename) returns a generator. I added map(str.upper, xxx) there to make it more it make sense.
But the point should be obvious, without generators that would potentially consume a lot of memory.