[plt-scheme] Closures

From: hendrik at topoi.pooq.com (hendrik at topoi.pooq.com)
Date: Mon Nov 5 11:54:19 EST 2007

On Mon, Nov 05, 2007 at 10:39:30AM -0500, Joel J. Adamson wrote:
> Howdy List,
> 
> Can someone give me an intuitive idea of closures, perhaps a clever
> analogy or metaphor?
> 
> My question is really motivated by some confusing usage: I understand
> what a closure is frome set perspective, but people speak of closures
> as though they are something function-like, as in one can invoke a
> closure.  Schemers speak of "using closures" fairly often.

Ah.  Let's say you're a function.  You need the values of some names in 
your environment in order to, well, function.  No, I didn't intend the 
pun.  You get carried away to some faroff place, perhaps in Amito, 
Japan, where you've been called.  You still need the values of those 
names in your environment.  Now to get these values, you'd better have 
them packed away in your suitcase.  So your suitcase, which you packed 
back at home when you were just a little lambda-expression, is, 
effectively, part of you.

Now this package of code-plus-environment, which closes off all the 
dangling reference a function might have, is called a closure.  
Abd indeed, because it is the closure of a function you can call it.

There are other kinds of closures, such as continuations, but they too 
can be called Indeed, you can probably get into an argument saying 
that continuations are an *other* kind of closure.

I don't even know if Scheme has any kinds of closures that can't be 
called.  I don't know of any.  So if your frame-sets are different 
(you seem to think they can't be called) perhaps you could give me an 
intuitive explanation what *they* are.

-- hendrik


Posted on the users mailing list.