4 ms·
Is this how news.ycombinator.com runs? (Ctrl+F for "Closures Simulate Subroutines")
- nostrademons 19y agoI always assumed it was, and that the closures are stored in the user's session (in memory, on the server). You notice that if you leave a comment reply box up on the screen long enough, you'll get "Unknown or expired session" when you try to submit, and have to back up to the main comment page before you can try again?
- ced 19y agoIf they expire sessions in order to avoid losing memory over users leaving without ever calling the closure, their timer seems short for what it gains. The link name "fnid=" is a pretty strong giveaway as to what is underneath.
- ralph 19y agoYes, I find it too short and the end result is annoying but passable for the audience here. Non-technical users wouldn't be so understanding I suspect. How are hash keys deleted? Age? Or are just the last N generated ones kept?
- ced 19y ago[silly test to see if they remove the closure from the HT once it's used, and the answer seems no]
- pg 19y agoCorrect, unless the closure explicitly removes itself when executed, of course.
- pg 19y agoFor calls that don't need to know about more state than their arguments, we just use an ordinary url with arguments. Otherwise we make a closure and store it in a hash table in memory, and make the url be x?fnid= where the argument is the hash key. When an http request comes in, we call the corresponding closure. Sometimes what to do next after following a link generated by the closure (e.g. what to do after logging in when you're not logged in and you submit a link through the bookmarklet) is part of the state of the closure; in that case it's a bit like a continuation. We keep only the most recently generated 20,000 closures. When you click on a link that says it has expired, that means either it has been purged from the closure table, or that we've restarted the server.
- malkia 19y agoIsn't there a risk, that someone can (accidentally or not) enter hash-code of someone else's "closure"?
- malkia 19y agoIsn't there a risk, that someone can (accidentally or not) enter hash-code of someone else's "closure"?
- mdakin 19y agoOne could avoid that problem by keeping track of the owner of each closure and ensuring the user is properly authenticated before calling the closure.
- pg 19y agoThe code explicitly protects against that.
- papersmith 19y agoIf access to the closures are session-specific, you'll have to hijack the session to do that.
- papersmith 19y ago"in that case it's a bit like a continuation." Doesn't MzScheme (assuming it's what Arc is built on) have first-class continuation already?
- nickb 19y agoPaul, could you enlighten us how well does this type of development (Lisp macro/closure based) integrate with JS and Ajax? I'm interested in asynchronicity of the Ajax... Ruby and Python with Protoype and Scriptaculous make this very easy indeed...
- pg 19y agoHow much Ajax do you see on this site? (The answer is that I don't know, because I haven't tried.)
- avibryant 19y agoIn my experience with Seaside (which uses roughly the same technique), extremely well. There's a demo site at http://scriptaculous.seasidehosting.st/, http://scriptaculous.seasidehosting.st/, fwiw.