Do we need generators/continuations?

4 views
Skip to first unread message

Andrew

unread,
Mar 2, 2007, 2:08:04 PM3/2/07
to tiscript
Generators are functions that use 'yield' keyword to return 'next
value' of some sequence
http://en.wikipedia.org/wiki/Generator_%28computer_science%29

Technically this is relatively simple to do as all mechanisms for that
are already in place.

Comments anyone?

Main motivation of having generators is to provide custom enumeration
facilities. Currently
for(var i in something) ...
works only for intrinsic collections like property/value lists (a.k.a
objects), arrays and indexes in persistent storages (DB)

E.g. in Sciter someone will want to write element filters

for( var paragraph in some_element.all("p") )
{
....
}

Where filter all(selector) could be something like this:

function Element.all(selector)
{
var child = this.first;
while(child)
{
if( child.match( selector ) )
yield child;
cheld = child.next;
}
}

bbr...@gmail.com

unread,
Apr 12, 2007, 5:37:25 PM4/12/07
to tiscript
I would love to see generators. I have additional uses for myself.
There are some nice thread-like uses of generators that I would like
to explore.

Andrew

unread,
Apr 13, 2007, 1:42:49 AM4/13/07
to tiscript

Do you mean something close to cooperative multitasking using
generators?

bbr...@gmail.com

unread,
Apr 13, 2007, 4:10:01 AM4/13/07
to tiscript
Yes, precisely. And between closures and generators, you can store a
lot of state in a continuation. They add a lot of new possibilities
for such a small construct. Of course, custom iterators are probably
the most useful and common case.

Reply all
Reply to author
Forward
0 new messages