develooper Front page | perl.perl6.internals | Postings from December 2001

Generators -- Icon, Python, YAML and YATL

Thread Next
From:
Clark C . Evans
Date:
December 30, 2001 23:33
Subject:
Generators -- Icon, Python, YAML and YATL
Message ID:
20011231024819.A20910@doublegemini.com
Hello.  I was wondering if Parrot is going to support
Generators.   A generator is a function that returns
multiple times, and I believe, was first made available
in the language ICON.  Now, ICON may have taken it a
bit too far (everything is a generator), however, 
Python's newest version supports generators.  

You can think of a generator as a resumeable function.
Essentially, it boils down implementing a call *tree*
instead of a call stack.  When a generator is initiated,
a new branch is pushed on to the current node.  For
each invocation of the generator, the branch remains.
And when the generator returns/terminates, the branch
is removed from the current node.  A function is a 
special case of a generator, where its invocation
and return are the same.  A call tree with only
functions looks just like a stack since each node
has only one branch.

This is a fundamental design change, but if Parrot is
not all that far along; it may be very worth while.  
When processing information from multiple sources, one 
typically has to either resort to "C" code and use
long-jumps, implement your own generator mechanism,
or use a threading library.   In most cases, people just
use multiple threads.   Interestingly, this common use 
case does not require threads.  Threading is just overkill.  
But, a single program stack won't do either.  

This processing pattern occurs, for instance, in XSLT, the 
XML to XML transformation language.  With generators, XSLT
implementation is almost trivial. Without generators, well, 
it's a bear.  I'm sure the processing pattern occurs
in all kinds of network programming as well.  As soon
as more than one socket is open, generators become very 
useful.

I ask this for two reasons.  First, I am/will-be using
generators in Python's new implementation, and I'd like
it if Python can be represented via Parrot.  Second,
I'm developing a transformation language of my own,
YATL (YAML Transformation Language) which is a YAML to
YAML transform.   I'd like this langauge to compile to
Parrot bytecodes.  However, without generators this
won't be possible.

Lastly, I close with an introduction.  I'm one of the
developers of YAML (YAML Ain't a Markup Language)
which you an read about at http://yaml.org; I'm going
to lurk on this list to ensure that YAML is capable
of serializing Parrot constructs... if you don't
mind me piping in here and there to ask questions...

Thank you so much,

Clark

-- 
Clark C. Evans                   Axista, Inc.
http://www.axista.com            800.926.5525
XCOLLA Collaborative Project Management Software

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About