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 | b521 ]

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.

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!

 From: 2008-10-08 06:45 am (UTC) (Link)
And now, go to sleep, woman! :) It must be 3am there!

Congrats on the getting of it!
 From: 2008-10-08 03:45 pm (UTC) (Link)
Nice!
 From: 2008-10-08 05:41 pm (UTC) (Link)
 From: 2008-10-08 05:57 pm (UTC) (Link)
Yeah! I just saw it and was about to tell you!

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

something like:
`X + recurse(param) # naive#versusrecurse(param, X) # reified accumulator#versusrecurse(param, lambda(Y){ X + Y } ) # reified accumulating action`

From:
2008-10-08 10:26 pm (UTC)

### this is all very Monady.

Yes. Because that is where monads come from.
From:
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.
 From: 2008-10-09 02:27 am (UTC) (Link)

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!!

 From: 2008-10-09 02:39 am (UTC) (Link)
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?