Continuations In Mozilla
I came upon two interesting subjects recently:
In the spirit of Roman Porotinkov's AOP posting, I'd like to add this attempt to explain continuations with a short implementation in JavaScript. Here's are three sample functions that we'll work with...
Here are some sample invocations...
Up to this point, the
That's it! Next, we'll convert our sample functions by "continuate"-ing them...
Now, let's go get some continuations...
How does it work? The calls to
This is just a poor-man's continuation-passing style transformation. The function invocations of capitalize() and prettify() have been converted to take an extra closure parameter -- the continuation. Of course, JavaScript supports first-class lexical closures. Way to go Brendan.
The
At line #b in the sample functions, the variable
About
We don't have Lisp-style macros in JavaScript, which would have made this more powerful (but harder to understand?). But, modern versions of JavaScript (JavaScript 1.5, in Mozilla Firebird) support
Anton van Straaten on Lambda-the-Ultimate says that "a continuation *is* a closure". And, we've just walked through continuations implemented as closures. A lot of closures. Just see how unpretty the
Finally, with my understanding to continuations and how much state and resources they can chew up, I don't see how continuation-based web programming (like Seaside) can scale up.
Other caveats:
- Lambda the Ultimate's Continuations discussion
- Aspect-oriented-programming in JavaScript in 20 lines of code
In the spirit of Roman Porotinkov's AOP posting, I'd like to add this attempt to explain continuations with a short implementation in JavaScript. Here's are three sample functions that we'll work with...
function capitalize(str) {
// #a - next line to be explained soon.
capitalizeReturns[capitalizeReturns.length] = __cont__;
return str.charAt(0).toUpperCase() + str.substring(1);
}
function prettify(firstName, lastName) {
// #b - next line to be explained soon.
prettifyReturn = __cont__;
firstName = capitalize(firstName);
lastName = capitalize(lastName);
return firstName + " " + lastName;
}
function formalName(personName, prefix) {
var parts = personName.split(',');
personName = prettify(parts[1], parts[0]);
return prefix + " " + personName
}
// #c - the following vars will be explained soon
var __cont__ = null;
var prettifyReturn = null;
var capitalizeReturns = [];
Here are some sample invocations...
formalName("yen,steve", "Mr."); // returns "Mr. Steve Yen"
formalName("bush,george", "President"); // returns "President George Bush"
Up to this point, the
__cont__ value has been null. Let's make __cont__ useful by introducing some continuation conversion functions...
function continuate(funcName) {
var funcText = uneval(this[funcName]);
if (funcText.charAt(0) == '(')
funcText = funcText.slice(1, -1);
funcText = funcText.replace(/return\s*(.*?);/g, "return __cont__($1);");
while (true) {
var newStr = funcText.replace(/(var\s+)?(\w+)\s*=\s*(\w+)\s*\((.*?)\);/,
"return $3($4, function($2) {");
if (newStr == funcText) break;
funcText = newStr + ")}";
}
funcText = funcText.replace(/\{/, "{ var __cont__ = getContinuation(arguments); ");
return this[funcName] = eval("(" + funcText + ")");
}
function getContinuation(args) {
var cont = args[args.length - 1];
if (cont != null && typeof cont == "function")
return cont;
return function(res) { return res; }; // An identity function.
}
That's it! Next, we'll convert our sample functions by "continuate"-ing them...
continuate("formalName");
continuate("prettify");
continuate("capitalize");
Now, let's go get some continuations...
var prettifyReturn = null; // holds the continuation to prettify()
var capitalizeReturns = []; // holds the continuations for capitalize()
formalName("bush,george", "President"); // returns "President George Bush"
prettifyReturn("Bill Clinton"); // returns "President Bill Clinton"
capitalizeReturns[0]("George H"); // returns "President George H Bush"
capitalizeReturns[1]("Washington"); // returns "President George Washington"
How does it work? The calls to
continuate() transformed the original three sample functions to look like...
function capitalize(name) {
var __cont__ = getContinuation(arguments);
capitalizeReturns[capitalizeReturns.length] = __cont__; // same line #a as above
return __cont__(name.charAt(0).toUpperCase() + name.substring(1));
}
function prettify(firstName, lastName) {
var __cont__ = getContinuation(arguments);
prettifyReturn = __cont__; // same line #b as above
return capitalize(firstname, function(firstName) {
return capitalize(lastName, function(lastName) {
return __cont(firstname + " " + lastName);
})
})
}
function formalName(personName, prefix) {
var __cont__ = getContinuation(arguments);
var parts = personName.split(",");
return prettify(parts[1], parts[0], function(personName) {
return __cont__(prefix + " " + personName);
})
}
This is just a poor-man's continuation-passing style transformation. The function invocations of capitalize() and prettify() have been converted to take an extra closure parameter -- the continuation. Of course, JavaScript supports first-class lexical closures. Way to go Brendan.
The
getContinuation() function works because JavaScript supports variable number of function call arguments (varargs). So, we can also tack on a continuation closure as the last argument to our function calls and retrieve it using arguments[arguments.length - 1].
At line #b in the sample functions, the variable
prettifyReturns is assigned the continuation closure for the prettify() invocation. At line #a, since capitalize() is invoked twice, first on "george", second on "bush", we use an array (capitalizeReturns) that records those 2 continuation closures.
About
continuate():
We don't have Lisp-style macros in JavaScript, which would have made this more powerful (but harder to understand?). But, modern versions of JavaScript (JavaScript 1.5, in Mozilla Firebird) support
uneval(). With that, we can apply the popular bag-o-regular-expressions to do our function text munging. The regexps I put into continuate() really only scratch the surface of possible transformations. So far, they only convert the following function call styles: var x = foo(args...) and x = foo(args). I'm sure if you had a real JavaScript parser (maybe even one written in JavaScript), you could try a full continuation transformation approach that Paul Graham sketches out in On Lisp. But, none of us have that much free time.
Anton van Straaten on Lambda-the-Ultimate says that "a continuation *is* a closure". And, we've just walked through continuations implemented as closures. A lot of closures. Just see how unpretty the
prettify() code became, and while easy to understand, it'll be even slower to run.
Finally, with my understanding to continuations and how much state and resources they can chew up, I don't see how continuation-based web programming (like Seaside) can scale up.
Other caveats:
- I developed this using standard Rhino, the JavaScript 1.5 implementation in Java.
- It only works in JavaScript 1.5, hence this will (likely) work in Mozilla Firebird and (definitely) not in IE, because of
uneval(). - By using varargs in this toy implementation, it means that your functions can't also use varargs cleanly.

100 Comments:
Good design!
[url=http://kugffmwp.com/rfua/zsvk.html]My homepage[/url] | [url=http://bgqwtdwa.com/vqkd/sycp.html]Cool site[/url]
Great work!
My homepage | Please visit
Thank you!
http://kugffmwp.com/rfua/zsvk.html | http://abqgxyxu.com/auhr/yxkl.html
Hello
That was useful info...thanks and Welcome to live chat hot babe chat. If you search the aldactone? Click here - aldactone
Enjoy
Hello. Alone on Valentine's Day? Adult Live Chat & movie pages Try to find partner in your area!
for fun
lolita chin
lolitas 13
lolitas kid
free anal sex
lolita picture
lolita suck
lolita cp terra loltobbs ftp lol
lolita vip lolitas virgins bbs
lolita lolly fuck movie children
lolita chin
lolitas 13
lolitas kid
free anal sex
lolita picture
lolita suck
lolita cp terra loltobbs ftp lol
lolita vip lolitas virgins bbs
lolita lolly fuck movie children
Hi all!. Use these helpful search engines TFO search & sex and try to find all you need in your area!
Enjoy
Stop HARD WORKING)))
Only for man useful links )))
FOR FORCE buy viagra FOR REST casino
and for your girlfriend ))))
Flower
i think its will be usefull ))))))
I found a lot of interesting information for me ))) here )))) and i start prepare to 8 march )))))
air line ticket
I start to women day prepear
I start to women day prepare……
I buy flower, viagra and xanax .....))))
But I have problem. I haven't women….
Help me please.
I had no words to say. I just moved on top of her and hugged her right from top to bottom.
My naked body wanted to feel every inch of her body, and I was caressing her all over like mad.
free tiffany lolita soon began to respond with equal vigor, Her right palm reached my rigid japanese blowjob and began pumping it slowly.
I was so damn horny, but I did not want to waste my semen, just masturbating. I wanted more...I wanted to fuck my cousin there and then.
"Oh free lolita porn...this is too much...I don't think I can keep my promise...please let me remove your panty and let me feel my kiddy sex fuck on your pussy"...I pleaded.
To my utter surprise, without any resistance, free pedo tpg raised her hips, and in a swift action removed her panty.
"You will only feel your pedo russian around my pussy...not inside..OK?" Jenna Jameson Porn insisted.
I almost got angry, and said "OK, but let me play with your tits at least," and moved my pedophile fucking towards her cleavage.
I had no patience to seek her permission. I just pulled her bra straps and and quickly exposed he huge melons.
My mouth instinctly reached her left breast while my right hand was at her right tit. I sucked her like an infant,
expecting to find milk, while my palm was squeezing and kneading her other tit.
My sister and I love each other, but we fight constantly. We're always saying something rude about one other's hair, clothes, whatever, it doesn't matter, we quarrel. It's getting to the point were free celebrity sex clip will put in ear plugs if he's home with us for too long.
The other night, we thought Daddy might turn us over on his knee like he did when we were younger. We were in the bathroom, standing side by side. I looked over and up at my sister; I hated the fact that she was taller than me. She stands five foot seven inches tall, and I a mere five foot even. I think I also resented the fact that she was older than me. We're two years apart, she's 21 and I'm 19. We both have red hair, blue eyes, and freckles, some people have mistaken us for twins, but we're a year apart. Our bodies are different, she doesn't have much in the way of boobs, 36A, is all her cup size is, and I tease her about it all the time. Me, my boobs are a 36D. She doesn't have much in the way of hips either, very narrow she is, and I tell her she looks like a boy, which pisses her off. I got the better body entirely, I have a very shapely figure, and no one could ever mistake me for a boy. I was telling her that she needed to change her outfit, or buy clothes that fit her better. All her clothes drape o
ff of her like potato sacks; she was yelling at me, telling me that I dressed like a slut and I should be more conservative, when free childporn gallery burst through the door.
"That's enough! I want to hear no more from either one of you! You are driving me insane! You two are too old for this!"
My sister's first reaction is to get defensive and I let her go first.
"Dad, she started it!"
I looked up at Daddy sheepishly.
"No I didn't Daddy. I was just being honest. I can't help it if she can't stand to hear some criticism."
Daddy looked down at me. He knew what I was doing, but he always sided with me.
"You aren't dressed very well at all, free cross stitch patterns."
"You always side with her!"
She turned and gave me a mean look and I stuck my tongue out at her.
"Jessica! That's enough from you too."
I put my eyes down and nodded my head.
"Sorry Daddy I won't do it again."
My sister humphed my way and I moved past her. I stood on my tiptoes and kissed Daddy's cheek. "Sorry to make you angry Daddy."
He patted me on the head and smiled down.
"It's okay Darling. I just wish you two girls would get along."
"I'll try real hard Daddy."
I gave him another kiss, and as I got back behind him I stuck my tongue out at my sister again.
"Daddy! Look! Look what she's doing!"
Daddy didn't turn around.
"That's enough free digimon hentai pic! Get on out of here and go to bed!"
The bickering continued of course, until there was a break when Eliza was out with her boyfriend. I was in my room, reading and listen to music, actually enjoying the fact that she wasn't at home. I really hated fighting with her, but I couldn't ever stop myself from doing it. I heard the front door close and Eliza run up the stairs. I also heard Daddy yelling.
"Eliza, is everything alright?"
"Fine, Daddy, everything's fine!"
From the tone of her voice I knew she was okay. So, I went back to reading. I only got a few lines into the book when my door burst open and in came Eliza looking all flushed and fluttered.
"What's wrong? What happened?"
I fought with my sister a lot but I felt protective over her as well.
"Nothing. Well, okay something happened, but it wasn't wrong."
"What? You lost me somewhere in there."
"Oh Jess, it was fuckin' great!"
My eyes widened, my sister doesn't speak like that.
"Okay, what was it? C'mon you gotta tell me!"
"I did it."
I watched Eliza go to the door, check the hall, and then close the door completely.
"You did what?"
"You know!"
"No, I don't. What did you do?"
"Don't make me mad! Not tonight!"
"I'm not trying to make you mad; I don't know what the hell it is you're talking about."
"I had sex."
"Oh, that it?"
"What do you mean, is that it?"
"Well, by the way you came in here I thought maybe you'd had the shit fucked outta ya or something. Just having sex isn't anything special."
"You've had sex before?"
event jobs
Best flower for you girlfriend
BEST FLOWER
soma or here phentermine
Great article! Thanks.
Thanks for interesting article.
Nice! Nice site! Good resources here. I will bookmark!
I see first time your site guys. I like you :)
Excellent website. Good work. Very useful. I will bookmark!
If you are an erectile dysfunction patient and the disorder is wreaking havoc in your sex life then discuss your problem with a doctor as soon as possible. Once you approach a physician, the doctor is likely to provide you Viagra prescription which further entitles you to obtain Viagra from viagra stores. If you administer Viagra in accordance with medical instructions, bearing in mind all the essential Viagra side-effects and precaution details, you would find yourself considerably relieved from the shackles of impotency.
49RO2e You have a talant! Write more!
xJfp1k Good job!
Erectile Dysfunction is regarded as the most prevalent male sexual disorder and Viagra, the Pfizer manufactured medication is considered to be the most effective treatment of erectile dysfunction by physicians as well as patients worldwide. People suffering from erectile dysfunction instantly opt for Viagra and Viagra related information online as well as in various offline sources in order to start off their anti-impotency treatment successfully. If you are an erectile dysfunction patient, you can seek out Viagra details on several authentic online sources and more especially, the sitemap section at buy-Viagra-with-us.com contains informative Viagra links that would provide you significant Viagra details and ensure your successful treatment with the drug.
coWjQc The best blog you have!
lB1wM2 Magnific!
Nice Article.
Please write anything else!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Wonderful blog.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Magnific!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Magnific!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
SpdRA0 write more, thanks.
Magnific!
Please write anything else!
Hello all!
Nice Article.
Wonderful blog.
Wonderful blog.
Magnific!
Wonderful blog.
Thanks to author.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Thanks to author.
Please write anything else!
C++ should have been called B
Clap on! , Clap off! clap@#&$NO CARRIER
Suicidal twin kills sister by mistake!
A flashlight is a case for holding dead batteries.
When there's a will, I want to be in it.
The gene pool could use a little chlorine.
Give me ambiguity or give me something else.
A lot of people mistake a short memory for a clear conscience.
Change is inevitable, except from a vending machine.
Lottery: A tax on people who are bad at math.
When there's a will, I want to be in it.
Ever notice how fast Windows runs? Neither did I.
Oops. My brain just hit a bad sector.
Oops. My brain just hit a bad sector.
Energizer Bunny Arrested! Charged with battery.
Give me ambiguity or give me something else.
All generalizations are false, including this one.
C++ should have been called B
Build a watch in 179 easy steps - by C. Forsberg.
Wonderful blog.
Change is inevitable, except from a vending machine.
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Oops. My brain just hit a bad sector.
Friends help you move. Real friends help you move bodies.
Nice Article.
Calvin, we will not have an anatomically correct snowman!
Suicidal twin kills sister by mistake!
Suicidal twin kills sister by mistake!
Ever notice how fast Windows runs? Neither did I.
Good job!
Please write anything else!
I'm not a complete idiot, some parts are missing!
Hello all!
Oops. My brain just hit a bad sector.
Suicidal twin kills sister by mistake!
A flashlight is a case for holding dead batteries.
Build a watch in 179 easy steps - by C. Forsberg.
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Suicidal twin kills sister by mistake!
Give me ambiguity or give me something else.
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Hello all!
Friends help you move. Real friends help you move bodies
Build a watch in 179 easy steps - by C. Forsberg.
Energizer Bunny Arrested! Charged with battery.
Ever notice how fast Windows runs? Neither did I.
Change is inevitable, except from a vending machine.
Friends help you move. Real friends help you move bodies.
The gene pool could use a little chlorine.
A flashlight is a case for holding dead batteries.
Nice Article.
Give me ambiguity or give me something else.
Post a Comment
<< Home