Are python's generators / yield possible in perl?

N

Nomen Nescio

Does perl have an equivalent to python's generators? I want
to be able to basically call yield() instead of return() to implement
iterators. If this exists, can XS code access it via perl guts?
 
C

Chris Johnson

Nomen said:
Does perl have an equivalent to python's generators? I want
to be able to basically call yield() instead of return() to implement
iterators. If this exists, can XS code access it via perl guts?

It might be better to explain what you want to do than assume we know
Python.
 
C

Chris Johnson

Chris said:
It might be better to explain what you want to do than assume we know
Python.

Alright, I've looked them up, and to answer your question, not in
perl5. There is a module on cpan called coroutine0, but it is extremely
ugly.

Incidentally, it took me all of five minutes to look up Python's
generators, find a link to perl coroutines, and then Google for perl
coroutines and find that they're to be implemented in Perl6, though a
few people have had a go at implementing them as modules in Perl5.
Perhaps you should do a little research next time?
 
B

brian d foy

[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]

Nomen Nescio said:
Does perl have an equivalent to python's generators? I want
to be able to basically call yield() instead of return() to implement
iterators. If this exists, can XS code access it via perl guts?

Although you might not get exactly what you want, Mark Jason's
Higher Order Perl will get you most of the way there.

http://hop.perl.plover.com/

See his chapter on iterators.
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top