Re: [Vala] Implicit lamdas/closures



On Tue, Sep 16, 2008 at 6:43 PM, Jürg Billeter <j bitron ch> wrote:
On Tue, 2008-09-16 at 15:39 -0700, Christian Hergert wrote:
I absolutely love the yield idea, very python-twisted'ish.  Lets make
sure the yield can return a value as well so we can have the
following:

var value = yield obj.do_something ();

Sure, return values should certainly be possible.

I'd love to see this in Vala - it would make asynchronous programming
much nicer. Would there be a syntax for specifying what types can be
sent in to the iterator/coroutine (assuming that the yield syntax
could be used for general iterators), or would yield always have to be
used with the _async/_finish API (and value's type inferred from the
sync version of the call)? Also, what would the C API look like for
these - functions that return GClosures or automatically-generated
sync/async versions of the function? I'm guessing that Vala could
automatically determine which one to do if it sees that you're
returning the result of a method marked as async-able, or maybe there
should be different keywords for either case... For example:

string do_something(Socket sock) {
    try {
        yield sock.connect();
    } catch (Error e) {
        return null;
    }

    var data = yield socket.read(5);

    return data;
}

Might be nice if this generated do_something, do_something_async, and
do_something_finish automatically.

-- 
Samuel Cormier-Iijima <sciyoshi gmail com>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]