Re: [Vala] Implicit lamdas/closures



2008/9/16 Christian Hergert <christian hergert gmail com>:
This sounds particularly interesting to implement.  As we would almost
certainly need some sort of "Async Handle" to work with.  .NET has
IAsyncResult, Twisted has Deferred, etc.  What makes this tough is that it
would require some sort of addition to GLib unless we were to require an
extra library like Gee.  However, I guess we could generate a special struct
that is used for this handle.

GLib has GAsyncResult which likewise follows the IAsyncResult pattern,
in the GIO library. Unfortunately as there isn't a bottom library for
such items (GObjects and interfaces with general usefulness), it had
to be stuck in GIO. But it also makes sense as GIO itself desperately
needed a way to generalize asynchronous programming.

-A. Walton


Of course, I could be totally wrong here and someone may have a clever way
around this.  I'll let it stew in my head over night; anyone else have
thoughts on this?

-- Christian

On Tue, Sep 16, 2008 at 4:28 PM, Samuel Cormier-Iijima <sciyoshi gmail com>
wrote:

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>


_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list





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