Wednesday, April 07, 2010

Delimited continuations? In ECMAScript?

Well, no.

Besides breaking a lot of language invariants, first-class continuations would be a nightmare for portability, since different implementations implement different API's natively. Either you mandate capturing continuations across native frames, which is a hardship for implementers and a performance-killer, or you don't, which causes observably different behavior across browsers when they place native delimiters at different points in the continuations-- leading to lots of painful bug reports and nasty market dynamics where everyone has to tailor their implementations to track the most popular.

So that won't happen. But!

JS 1.7 introduced Pythonic generators, which allow you to suspend a single function activation. This alleviates some of the painful CPS patterns people have to use on the web to interact with the event-loop-concurrent, single-thread-of-control semantics of JavaScript on the web. But it's also a little ad hoc. And Kris Zyp recently made the helpful suggestion that we could explore a design for a simpler, more general single-frame continuation-capture operation for Harmony.

What we're talking about here is a restricted version of delimited continuations: the delimiters are implicit--they're at function boundaries. But otherwise it's very much in that space. And there's a loooot of prior work on this topic. I'll post later with a little background and some notes about the design space of delimited continuations for ES.


Mitch said...

I think I understand scheme's call/cc, and I was really excited originally to hear that kind of thing proposed for ES. Then later, on LTU, Brendan explained the script/native/script thing and I was sad.

I don't really get delimited continuations yet, I've seen Oleg Kiselyov posting about them a lot but I don't understand just about everything he writes. Still, it's really exciting to see some kind of continuations show up again in ES context; I haven't really followed the ES email lists for a while but maybe it's time to start reading them again.

TL;DR - Yay!

jto said...

I think Lars Thomas Hansen's complaint about single-frame continuations is that they break lambda abstraction. Beta reduction changes the meaning. What do you think about that?

Dave Herman said...

Lars Thomas Hansen's complaint about single-frame continuations is that they break lambda abstraction.

Well, full continuations certainly do expose details of lambda abstractions. The main issue is if a library function takes a funarg and calls it, the funarg might capture the continuation and use it multiple times. (You can think of this as the funarg "highjacking" the control flow.) Turns out lots of standard Scheme libraries like map are buggy because they don't expect control to return multiple times.

I suspect the situation isn't as bad in the case of single-frame continuations, though. Did Lars tell you this in person, or is he on record somewhere publicly? I'm having drinks with him on Wednesday, so I'll ask him myself. :)

Beta reduction changes the meaning. What do you think about that?

Well, I'm not sure what you mean, exactly. The beta rule stays the same in the presence of call/cc. It just means that some of the invariants about function abstraction are gone.

Dave Herman said...

PS I should say, lots of implementations of standard Scheme libraries. Didn't mean to imply the spec is buggy.

jto said...

The beta rule stays the same in the presence of call/cc, yes. But not in the presence of single-frame continuations (or generators) because there every function call implicitly installs a delimiter.


(function () { return EXPR; })()

I'm talking about the difference between these two in terms of what is captured if EXPR contains f->(x).

This is something lth mentioned to me while ES4 was going on. However now I'm a bit worried that I've misrepresented the importance of this objection compared to others; and it's been a year or two.

Dave Herman said...

I see what you're getting at now.

So first of all, there's no beta rule in JS, just an ad hoc semantics of functions, which are already exposed in the semantics: return is a delimited abort operation; arguments is function-specific; Function.arguments; Function.callee... heck, the spec even refers to function calls as "allocating an activation object" whose slots are the local variables.

That said, you're right that this hooks one more piece of semantics into the meaning of functions. If JS hadn't long ago already gone down this road in spades, I would whole-heartedly agree. (For example, it'd be a total non-starter for Scheme. And if the lambdas proposal weren't dead, they'd be specified not to be implicitly delimited.)

Another way of putting it: rather than "changing the beta rule" (which is just a reduction rule), this ruins beta-equivalence. But beta-equivalence already doesn't hold in JS.

Kanye Co Jamila said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

john smith said...

Great post, Thank you for sharing this amazing post, I really appreciate your work. | |

James Boond said...

Really great article, Glad to read the article. It is very informative for us. Thanks for posting

alexathomson said...

Get comprehensive round-the clock QuickBooks Support for all issues. The QuickBooks technical support team offers immediate assistance and can be reached by calling the QuickBooks Support Toll-free Number.

Mia Davis said...

Much thanks to you such a great amount for sharing, I trust you keep on composing soul next subject. | | | |

Smith John Live said...

Download and install the HP LaserJet Pro m404n driver
1.Go to the HP support site and download the driver
2.When you get the prompt choose the printer and then press download and run the HP Easy start
3.When prompted choose the printer and press the My print is not shown
4.Tap continue and then choose wireless network
5.Now follow the onscreen setup to finish the wireless network
To know more about the process of HP LaserJet pro m404n setup you can just give a call at. Also, drop in on our site for more steps on printer setup.

geeksquad said...

geek squad appointment |
best buy geek squad appointment |
best buy appointment |
geek squad appointment scheduling |
best buy geek squad appointment schedule | |

Unknown said...

Gradually, with the new digital dominating world the options have increased of installing any program to the device; is an innovative and productive way to download, activate and complete the installation of Norton antivirus.

finnjordan100 said...

AVG Secure is a designed to keep your digital info safe and secure. Learn about its pricing, security features, and more in this review. | |
Install AVG with license number |
AVG Download |

finnjordan100 said...

Webroot makes sure that you have the best security software products installed on your computer, it uses antivirus protection and a firewall, gives antispyware software, always keeps it up to date. | |
Install Webroot With Key Code

finnjordan100 said...

Webroot makes sure that you have the best security software products installed on your computer, it uses antivirus protection and a firewall, gives antispyware software, always keeps it up to date. | |
Install Webroot With Key Code

elibeth3636 said...

The AVG AntiVirus Free software offers protection against viruses, spyware, malware, trojan horses, worms, keyloggers, ransomware and a variety of other malicious threats. |

elibeth3636 said...

Trend Micro is best antivirus in this field because it uses multi-layered ransomware protection by working in three directions. |
Trend Micro Geek Squad | besbuypc

Mark William said...

AVG Antivirus we suggest purchasing always from official website . If you purchase from unauthorized websites then your system might get compromised. AVG is one of the best Antivirus who scan your whole device and keep eyes for the future as well. If you get any trouble during Installation you may also contact at Install avg with license number or AVG customer service phone number . AVG Support or AVG customer care keen to help their customers. You may also download AVG Internet Security from AVG antivirus is the best among many antivirus software, which is provided by AVG technologies. also Support on call by calling their AVG tech support or AVG Care Service .

greyhankin said...

Being the best streaming service in the US, Roku has a keen track of all your activities using the Roku account that you create. Roku also needs you to complete the for activating the account. Here are certain things that we assist you on to complete the Roku activation.
For any further queries on Roku com link Activation, feel free to contact our active customer care team, working round the clock at the toll-free number.

charlesbronson said...

Thank you for sharing excellent opinion. I am impressed by the details that you have going approximately for this website. I have more warn similar this blog. Click asleep to know these instruction
Norton setup || office setup |
Avast customer support number | Avast help & support Number

tech support said... 2652 6968 6978 5055

honlith said...

hp envy 5052 driver

Jeffery king said...

hp envy 5052 driver

Unknown said...

Did you realize there is a 12 word phrase you can communicate to your crush... that will induce deep emotions of love and impulsive appeal to you deep within his chest?

That's because hidden in these 12 words is a "secret signal" that fuels a man's instinct to love, cherish and guard you with his entire heart...

=====> 12 Words Who Fuel A Man's Love Response

This instinct is so hardwired into a man's brain that it will make him work harder than ever before to take care of you.

Matter of fact, triggering this powerful instinct is so essential to achieving the best possible relationship with your man that the second you send your man a "Secret Signal"...

...You'll immediately notice him expose his mind and soul for you in such a way he never expressed before and he will perceive you as the only woman in the galaxy who has ever truly appealed to him.

Roan said...

Dragon NaturallySpeaking remains the for Windows-based speech-to-text technology.
dragon naturally speaking | dragon naturallyspeaking
nuance dragon | nuance dragon naturallyspeaking

lily grace said...

You can get it from avg to protect your identity. Browsers also contain cookies which track user’ location, id, and much other information and can be harmful so that AVG AntiTrack can protect you.
For some devices, during installation, AVG AntiTrack may show SQL Error, which cannot let you use the application and so we have discussed the blog here.
install avg with license number
AVG antivirus is the security program that works after it’s activation with avg retail. It requires an activation product key to activate AVG’s working and to protect your operating system. |
avg download

lily grace said...

McAfee service offers trusted safety to protect data and devices. So, you can shop, surf & keep all your devices safe online with the convenience of a single subscription.
www mcafee activate | mcafee login my account |
www mcafee com login
mcafee livesafe login | my mcafee account |
mcafee activation code | my account

Mark William said...

Trend Micro Internet Security subscription is the single way to download the software on multiple devices through . Trend micro has become a superior antivirus program over many antiviruses due to its advanced protection features. trend micro download process becomes easy when you purchase the subscription.

Elegant IT Services said...

Nice Post...Thanks for sharing the Information...
Elegant IT Services

wilder zayn said... - Presently, technology is transforming at a quicker pace than ever. With all the growth in technology comes the increasing number of possibilities for cybercriminals to abuse. As a consequence, cybersecurity has become extremely essential in order to safeguard persona, consumer, and business information against various threats. visit on | |

Mark William said...

eset internet security can be installed quickly on each device if the user follows the correct procedure. You can follow the instructions below to install the setup on your devices such as Windows PC, Mac, or mobile device.