Re: yield and Promises

2011-10-21 Thread Jorge
On 20/10/2011, at 23:37, Brendan Eich wrote: On Oct 20, 2011, at 12:59 PM, Jorge wrote: the assert_invariants() at the next line might run in another turn of the event loop (when f() resumes), just as the callback does. No. Nothing in JS today, since it lacks coroutines or call/cc, can

Re: yield and Promises

2011-10-21 Thread Jorge
On 21/10/2011, at 11:07, Jorge wrote: And this has several (valuable, imo) advantages: - We aren't trashing the call stack on every async call: we can finally debug properly! - We can (finally!) catch the exceptions where and when it matters. - We can loop and control flow in the usual

Re: yield and Promises

2011-10-21 Thread David Herman
You can disagree with anything if you're allowed to change the terms of the discussion. :) Brendan said JS is run-to-completion, which means that if you call a function and control returns to you, no intervening threads of control have executed in the meantime. But then you changed his example

Re: yield and Promises

2011-10-21 Thread Brendan Eich
On Oct 21, 2011, at 9:34 AM, John J Barton wrote: Can anyone summarize how these proposals relate to Kris Kowal / Kris Zyp / Mark Miller Q library: https://github.com/kriskowal/q Did you see https://github.com/kriskowal/q/tree/master/examples/async-generators yet? In my experience,

Re: yield and Promises

2011-10-21 Thread David Herman
Hi Kris, Your proposal has a lot of similarities to http://wiki.ecmascript.org/doku.php?id=strawman:deferred_functions which was proposed this past spring. I'm not sure I follow what's top-down vs bottom-up about the two different approaches. Let me suggest some terminology that has

Re: yield and Promises

2011-10-21 Thread John J Barton
On Fri, Oct 21, 2011 at 9:41 AM, Brendan Eich bren...@mozilla.com wrote: On Oct 21, 2011, at 9:34 AM, John J Barton wrote: Can anyone summarize how these proposals relate to Kris Kowal / Kris Zyp / Mark Miller Q library: https://github.com/kriskowal/q Did you see

Re: yield and Promises

2011-10-21 Thread Mark S. Miller
On Fri, Oct 21, 2011 at 10:20 AM, John J Barton johnjbar...@johnjbarton.com wrote: On Fri, Oct 21, 2011 at 9:41 AM, Brendan Eich bren...@mozilla.com wrote: On Oct 21, 2011, at 9:34 AM, John J Barton wrote: Can anyone summarize how these proposals relate to Kris Kowal / Kris Zyp / Mark

Re: yield and Promises

2011-10-21 Thread Brendan Eich
On Oct 21, 2011, at 10:20 AM, John J Barton wrote: My comment is entirely subjective and intended to be positive about Q. We like Q too. :-) The examples on the async-generators page cites above are clearer than the ones on the MDC generators page because they focus on next(). The strong

Re: yield and Promises

2011-10-21 Thread Jorge
On 21/10/2011, at 17:40, Eric Jacobs wrote: Jorge, Would it still be satisfying to you if instead of writing the call expression like this: try { response = asyncFunction(request); //might suspend execution } catch (e) { //whatever } //our code continues here we needed to write

Re: yield and Promises

2011-10-21 Thread Jorge
On 21/10/2011, at 21:23, Dean Landolt wrote: On Fri, Oct 21, 2011 at 3:20 PM, Jorge jo...@jorgechamorro.com wrote: On 21/10/2011, at 17:40, Eric Jacobs wrote: Jorge, Would it still be satisfying to you if instead of writing the call expression like this: try { response =

Re: yield and Promises

2011-10-21 Thread Eric Jacobs
Jorge wrote: or some other creative way of statically encoding the might suspend execution condition into the syntax? Yes, of course, it would be fine. Why ? Because this is the crux of the run-to-completion debate that we're immersed in. Right now, JS has run-to-completion, where

Re: yield and Promises

2011-10-21 Thread Brendan Eich
On Oct 21, 2011, at 12:49 PM, Eric Jacobs wrote: The catch is, of course, that all code which either can yield, or can call other functions which yield, must have the yield keyword there, to mark that run-to-completion invariants will end at that point. This seems like a very reasonable

Re: yield and Promises

2011-10-21 Thread John J Barton
On Fri, Oct 21, 2011 at 10:46 AM, Mark S. Miller erig...@google.com wrote: On Fri, Oct 21, 2011 at 10:20 AM, John J Barton johnjbar...@johnjbarton.com wrote: In particular, Q simplifies joining parallel async operations (XHR, postMessages, 'load', 'progress' events). Of course it may well

Re: yield and Promises

2011-10-21 Thread Eric Jacobs
Brendan Eich wrote: On Oct 21, 2011, at 12:49 PM, Eric Jacobs wrote: The catch is, of course, that all code which either can yield, or can call other functions which yield, must have the yield keyword there, to mark that run-to-completion invariants will end at that point. This seems like a

Re: yield and Promises

2011-10-21 Thread Brendan Eich
On Oct 21, 2011, at 2:03 PM, Eric Jacobs wrote: As a language end-user, I'm not sure that I would (or should) be concerned about the distinction between a deep continuation and a chain of shallow continuations. After all, the stack is just a chain of frames, and the mechanism by which

Re: yield and Promises

2011-10-21 Thread Kris Zyp
On 10/21/2011 11:01 AM, David Herman wrote: [snip] But there's more to it than just the interface. You fix a particular scheduling semantics when you put deferred functions into the language. I'm still learning about the difference between the Deferred pattern and the Promises pattern, but

Re: yield and Promises

2011-10-20 Thread Jorge
On 19/10/2011, at 23:34, Brendan Eich wrote: The other objection is that (ignoring some evil native APIs such as sync XHR) JS has run-to-completion execution model now. You can model assert_invariants(); f(); assert_invariants_not_affected_by_f_etc(); where etc means functions

Re: yield and Promises

2011-10-20 Thread Dean Landolt
On Thu, Oct 20, 2011 at 9:44 AM, Jorge jo...@jorgechamorro.com wrote: On 19/10/2011, at 23:34, Brendan Eich wrote: The other objection is that (ignoring some evil native APIs such as sync XHR) JS has run-to-completion execution model now. You can model assert_invariants(); f();

Re: yield and Promises

2011-10-20 Thread Brendan Eich
On Oct 20, 2011, at 6:44 AM, Jorge wrote: On 19/10/2011, at 23:34, Brendan Eich wrote: The other objection is that (ignoring some evil native APIs such as sync XHR) JS has run-to-completion execution model now. You can model assert_invariants(); f();

Re: yield and Promises

2011-10-20 Thread Jorge
On 20/10/2011, at 18:38, Brendan Eich wrote: On Oct 20, 2011, at 6:44 AM, Jorge wrote: On 19/10/2011, at 23:34, Brendan Eich wrote: The other objection is that (ignoring some evil native APIs such as sync XHR) JS has run-to-completion execution model now. You can model

Re: yield and Promises

2011-10-20 Thread Brendan Eich
On Oct 20, 2011, at 12:59 PM, Jorge wrote: assert_invariants(); f(); //might suspend execution assert_invariants(); // perhaps yes, perhaps no. There's no guarantee either. return; (Please trim cited text -- I know gmail hides it, which is a bug, but most mail user agents show it, and

yield and Promises

2011-10-19 Thread Kris Zyp
The topic of single-frame continuations has been discussed here before, with the current state of ES.next moving towards generators that are based on and similar to Mozilla's JS1.7 implementation. Generators are a powerful addition to the language and welcome (at least by me). However, I

Re: yield and Promises

2011-10-19 Thread Dean Landolt
This is a really great idea, Kris! A few comments inline... On Wed, Oct 19, 2011 at 1:11 PM, Kris Zyp k...@sitepen.com wrote: The topic of single-frame continuations has been discussed here before, with the current state of ES.next moving towards generators that are based on and similar to

Re: yield and Promises

2011-10-19 Thread Eric Jacobs
Kris Zyp wrote: I believe that the overwhelming need that is continually and constantly expressed and felt in the JS community in terms of handling asynchronous activity is fundamentally a cry for top-down controlled single-frame continuations (obviously not always stated in such terms,

Re: yield and Promises

2011-10-19 Thread Kris Zyp
On 10/19/2011 12:29 PM, Dean Landolt wrote: This is a really great idea, Kris! A few comments inline... [snip] If the value is not an object with a then property that is a function, the operand value is the immediate result of the evaluation of the yield expression and execution

Re: yield and Promises

2011-10-19 Thread Brendan Eich
On Oct 19, 2011, at 12:55 PM, Eric Jacobs wrote: Kris Zyp wrote: I believe that the overwhelming need that is continually and constantly expressed and felt in the JS community in terms of handling asynchronous activity is fundamentally a cry for top-down controlled single-frame

Re: yield and Promises

2011-10-19 Thread Brendan Eich
On Oct 19, 2011, at 10:11 AM, Kris Zyp wrote: The topic of single-frame continuations has been discussed here before, with the current state of ES.next moving towards generators that are based on and similar to Mozilla's JS1.7 implementation. Generators are a powerful addition to the

Re: yield and Promises

2011-10-19 Thread Brendan Eich
On Oct 19, 2011, at 2:34 PM, Brendan Eich wrote: The other objection is that (ignoring some evil native APIs such as sync XHR) JS has run-to-completion execution model now. You can model assert_invariants(); f(); assert_invariants_not_affected_by_f_etc(); Contrast with generators,