Wednesday, April 07, 2010

Harmony first-class activations

This morning I've been blogging about single-function activations for Harmony, the history and design space of continuations, and informal models and design sketches for control operators. A few more thoughts here.

One-shot continuations

(I won't try to model this in the framework I sketched earlier, because it introduces mutation, and then we have to add a heap to the model, and it gets mucky enough not to be worth it here.)

You can limit the expressivity of continuations to only allow control to enter them at most once. This is totally compatible with most any design we pick along the other dimensions. For example, in the semantics I sketched earlier, if the callee throws an exception, we throw back into the activation, and it becomes marked as un-reusable. So if the callee saved the captured continuation, invoking it later would be an error. But if the callee calls the captured continuation before returning and then returns normally, the caller skips past the continuation and returns normally.

There's one very subtle aspect of multi-shot continuations that is probably their single biggest liability: finally. In ES, when you execute a try block with a finally block, the finally block is guaranteed to be executed exactly once (assuming the body of the try block completes without an infinite loop and the program isn't abruptly terminated). Now, even with one-shot continuations, it's possible that you'll suspend the continuation before the try block completes and never resume it. But if you do resume it and the try block completes, it'll still execute the finally block exactly once.

With multi-shot continuations, you can resume that code as many times as you like, and that finally block will get executed again and again. (This is analogous to Common Lisp's unwind-protect and Scheme's dynamic-wind.) This is pretty subtle, and makes it harder to write correct "clean-up" code.

Implementing JS1.7 generators

One-shot, single frame continuations should be expressive enough to implement JS1.7 generators pretty easily. I sent a draft implementation of generators via one-frame continuations to the es-discuss list. As soon as there's a prototype implementation of single-frame continuations somewhere, it should be possible to test that code (mutatis mutandis).

My current preference

So far I sort of prefer the semantics I described earlier today, with one-shot continuations. But I need to implement and experiment before I trust my opinion. There are certainly questions of API and syntax design that aren't addressed by my design sketches. For that I'd really prefer to look at real callback-heavy DOM code and see what would fit the most smoothly.

23 comments:

jto said...

I don't think finally is especially troublesome in this regard. Multiple return would trample unstated assumptions of just about any program written in a stateful language like ECMAScript.

Multiple return is goto for ninjas. I'll be surprised if anyone wants that in ECMAScript. It seems like it would make it awfully hard to write any kind of secure code in the language.

Dave Herman said...

Multiple return would trample unstated assumptions of just about any program written in a stateful language like ECMAScript.

I mostly agree, which is why I stated that my preference is leaning towards one-shot. However, keep in mind that with one-frame continuations, it's only the code within that same function body that can be returned to multiple times. So you can tell whether multiple returns are possible simply by checking the immediate function body.

(Again, I still agree that finally gets far more tricky to get right, esp. as you say in a highly stateful language, and that this is probably too high a cost.)

Alex williams said...

Do you require HP printer setup for your mac operating system? Is your printer driver not suitable for macOS? Then visit the 123.hp.com/setup to get the software and driver for better functioning of your printer. You can also call our expert HP support team for services.

Unknown said...

Did you realize there is a 12 word sentence you can speak to your man... that will trigger deep emotions of love and impulsive attraction to you buried inside his chest?

That's because deep inside these 12 words is a "secret signal" that fuels a man's instinct to love, treasure and guard you with all his heart...

12 Words Will Trigger A Man's Love Response

This instinct is so built-in to a man's genetics that it will make him work harder than ever before to make your relationship as strong as it can be.

In fact, fueling this mighty instinct is so essential to getting the best possible relationship with your man that as soon as you send your man a "Secret Signal"...

...You will instantly notice him expose his soul and mind to you in a way he never experienced before and he will identify you as the only woman in the world who has ever truly interested him.

aditya said...


uml blackboard

Anonymous said...

Do you require any help regarding QuickBooks error which you are facing, types and how to rectify them? check Quickbooks Error Support in order to know the details of the Quickbooks error you are facing and how to rectify them.

kalichmpa said...

Good post thanks for share information.

high education learning
the education journey
still education
the education info
thee ducation training

Quickbooks error said...

Quickbooks faces incalculable mistakes, yet one of the major errors happens when
Quickbooks won't open in the wake of refreshing fora two or three minutes in a totally surprising state.

Joe Smith said...

on the off chance that you look for the product who has a fortification on the lookout and deal remarkable provisions to help clients Accountancy. ten you have 2 names who offers fantastic instruments quickbooks vs square

katie laner said...

You did a great job as your blog is a mixture of all the information which we collect through going on other pages so its the reader spot blog and i also have some interest in writing blog so i write a blog on quickbook error #15215 quickbooks error #15215 A QBs Repairing Guide
by consulting technicians so please go through it for once

periyannan said...

Nice blog post for reading and Thanks for sharing the wonderful article
internship websites in india
internship acceptance letter
internship experience letter
Internship permission letter
internship courses
Internship offering companies
internship mail format
Internship program in chennai
Internship training online
internship and apprenticeship difference

quickbooks error 6129 said...

When you access your QuickBooks company files or the database connection verification fails, the quickbooks error 6129 is likely to appear on your screen. As a result, you are unable to access your company's files in QuickBooks. Furthermore, the network that your QuickBooks is using will be unable to locate the server or your device that stores the file.

Nick mosan said...

When you try to open a company file, QuickBooks Error 6000 occurs. When numerous people are logged into the same company file at the same time, this can happen. When you are just trying to restore a prior backup of your files, Quickbooks error 6000 may occur.

Nancy said...

quickbooks error 15227 will occur when the workstation shuts down randomly and when the user switches off or turns on or when installing or updating QuickBooks.

Quickbooks tool hub said...

Intuit developed the Quickbooks tool hub, making it easier than ever to fix common QuickBooks application issues and inconsistencies. QB Tool Hub is a multi-functional asset that contains all of the tools needed to resolve common QuickBooks mistakes, such as File Doctor, QuickBooks Refresher, Condense Data Tool, PDF and Print Repair Tool, and others. This is an all-in-one multipurpose tool for dealing with company file problems, network issues, PDF and printing errors, data corruptions, password reset, and other issues.

QuickBooks unrecoverable error said...

great blog thanks for sharing information. if you have a query about QuickBooks Unrecoverable error so can install QuickBooks Tool is a very useful tool more info click here.

John Smith said...

QuickBooks error 15227 generally occurs while updating QB or installing its new version. It affects the overall performance of the software application so badly that, as a user, you can get easily frustrated. If you too have stumbled upon error 15227 in QuickBooks, then don’t worry, we are here to help you out.

Lily said...

QuickBooks file doctor is one amongst the repair tools used for resolution network and company problems that seem whereas performing on the quickbooks desktop file doctor .

nickmosan said...

Hey, I think u will check my article on Quickbooks error 80070057 this article mentions all the detail about How to fix Quickbooks error 80070057 so go to my page and check this article it is very useful to us.
Quickbooks error 80070057

William acker said...

Thank you for this informative blog share with us Quickbooks software is an accountancy software its easy to use and easy to handle if anyone wants to know more about this click nd read quickbooks database server manager

QuickBooks Support said...

In this comprehensive guide, we’ll discuss the reasons behind this error, its symptoms as well as effective methods to permanently resolve the QuickBooks 80070057” Incorrect parameter error. So, let’s begin.

How to Fix QuickBooks Error 80070057
QuickBooks Error 80029c4a

Mary said...

Thank you for the good article. Do you want to increase your clicking speed? Then visit this profile on clicker counter. By using this tool you can quickly estimate your click speed test score.

Appcul said...

Appcul is the best IT company. If you will choose this company so this will be a best choice for you because this is a Best Mobile app development company in Gurgaon if. Appcul will provide you with many more technologies and benefits. Here we have a team with good knowledge.