[plt-scheme] metaphors for local

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Nov 5 17:19:54 EST 2007

On Nov 5, 2007, at 5:08 PM, Prabhakar Ragde wrote:

> I'm enjoying these metaphors for closures. But while we are at it,  
> the instructors for the HtDP-based course I designed but am not  
> teaching this term are wondering about metaphors for local. They  
> want something akin to the stack of books on one's desk, or the  
> cache of library books on one's shelf. One of them suggested a  
> fresh piece of paper for local definitions which gets ripped up  
> (recycled?) after the body is evaluated, but I said, hmmm, you have  
> to be careful or you get dynamic scope, not lexical scope. So, does  
> anyone have any ideas? --PR

Most of what you have mentioned is flawed. Indeed, I watched a famous  
compiler writer give my lectures at Rice and getting this wrong. When  
the body of a local returns a value that refers to a local definition  
you're hosed with stacks, temporary write ups, etc:

  (define-struct foo (bar moe))

  (local ((define x (make-foo 0 #f))
          (define f ...)
    (make-foo x f))

Now think: f = (lambda () (set! x (+ x 1)) x)

;; ---

I recommend to think of a pile of papers except that every programmer  
has his own secret ink with which to definitions that only he can  
read. Don't ever throw any of these papers away! You might need them.

-- Matthias



Posted on the users mailing list.