?

Log in

No account? Create an account
I can't stop thinking about continuations! - Lindsey Kuper [entries|archive|friends|userinfo]
Lindsey Kuper

[ website | composition.al ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

I can't stop thinking about continuations! [Oct. 8th, 2008|02:23 am]
Lindsey Kuper
[Tags|]

We're in class, talking about how dynamic scope works: when you pass more than one argument to your closure, whatever else you pass is going to follow the dynamic flow of your computation rather than the rules of lexical scope. We're told that this idea is going to become important later, when we talk about other stuff.

All of a sudden, I realize that by "other stuff" we mean "continuations". I ask about this. "Yes."

Yes!

A week later, we're in class, talking about continuation-passing style. All of a sudden, an analogy occurs to me: Continuation-passing style is to accumulator-passing style as accumulator-passing style is to naive recursion. I ask about this. "Yes."

Yes!

I get it, I get it! I understand! I'm so excited!

LinkReply

Comments:
[User Picture]From: stacy_bird
2008-10-08 06:45 am (UTC)
And now, go to sleep, woman! :) It must be 3am there!

Congrats on the getting of it!
(Reply) (Thread)
[User Picture]From: pmb
2008-10-08 03:45 pm (UTC)
Nice!
(Reply) (Thread)
[User Picture]From: jes5199
2008-10-08 05:41 pm (UTC)
(Reply) (Thread)
[User Picture]From: lindseykuper
2008-10-08 05:57 pm (UTC)
Yeah! I just saw it and was about to tell you!

*bounce!*
(Reply) (Parent) (Thread)
[User Picture]From: kel_e_o
2008-10-08 06:45 pm (UTC)
Apparently Pear Programmers was one of their favorite team names too. Wasn't that your team name?
(Reply) (Parent) (Thread)
[User Picture]From: jes5199
2008-10-08 07:25 pm (UTC)
Pear Programmers! that's me and stereotype441 and j3h and boojum
(Reply) (Parent) (Thread)
[User Picture]From: lindseykuper
2008-10-09 01:53 am (UTC)
It was my friends' team name!
(Reply) (Parent) (Thread)
[User Picture]From: jes5199
2008-10-08 10:23 pm (UTC)
I don't quite have it.
when you pass more than one argument to your closure
what does that look like?

and your analogy... it's about reification?
something like:

X + recurse(param) # naive
#versus
recurse(param, X) # reified accumulator
#versus
recurse(param, lambda(Y){ X + Y } ) # reified accumulating action


this is all very Monady.
(Reply) (Thread)
[User Picture]From: pmb
2008-10-08 10:26 pm (UTC)

this is all very Monady.

Yes. Because that is where monads come from.
(Reply) (Parent) (Thread)
[User Picture]From: lindseykuper
2008-10-09 05:17 pm (UTC)

Re: this is all very Monady.

This is encouraging, because it means that maybe I'll understand monads soon.
(Reply) (Parent) (Thread)
[User Picture]From: lindseykuper
2008-10-09 02:27 am (UTC)

Well, okay. Say you want to evaluate a procedure of one argument (that's the only kind you really care about, because of currying). Your procedure looks like this:

(lambda (x) body)

So what do you do? Well, you'd evaluate it by evaluating body, but with x now bound in your environment, right? In other words, this all gets turned into a closure. You give x and body and the current environment to your closure-making machine, and what you get back is a procedure of one argument, but with the updated environment -- x bound to whatever -- baked into the closure.

But now suppose you wanted to pass an environment to the closure, too! This one could be a different environment every time, not like the one that's baked in. (In fact, you can't really call the thing a closure anymore. In my homework, I call it not-a-closure.) Now the new environment overshadows the old one when the closure is called! If you wanted a real closure, this is Very Bad. But if you wanted something that can change as the computation goes along, then maybe it's useful. So what does all this have to do with continuations? I guess I just saw a parallel between situations where you'd want this and situations where you'd want a continuation. Both require passing an extra argument that changes on every call.

And I don't know what reification is. I just calls 'em like I sees 'em.

Also, did you know that "monad" is also a term in music theory? For all intents and purposes just means a single pitch. But by analogy with "dyad" and "triad", it should mean "one-note chord". PARADOX!!

(Reply) (Parent) (Thread)
[User Picture]From: jes5199
2008-10-09 02:39 am (UTC)
when I say reify, I mean something like the process of taking something implicit (like the call stack) and replacing it with something explicit (like a parameter)

Now the new environment overshadows the old one when the closure is called

I'm not entirely sure what you mean here. Can you show code?
(Reply) (Parent) (Thread)
[User Picture]From: lindseykuper
2008-10-09 03:30 am (UTC)
Okay, then yeah, I guess reification is what I'm doing.

I just sent you a big pile o' code. I'd put it online somewhere, but posting homework solutions is probably frowned upon.
(Reply) (Parent) (Thread)
[User Picture]From: empty_fork
2008-10-09 06:19 am (UTC)
you made me care about this entirely-uninteresting-to-me topic for as long as I was reading your post.

way to excel along multiple vectors.
(Reply) (Thread)
[User Picture]From: lindseykuper
2008-10-09 05:18 pm (UTC)
I live to serve.
(Reply) (Parent) (Thread)