[plt-scheme] Closures
Matthias Felleisen <matthias at ccs.neu.edu> writes:
> On Nov 5, 2007, at 4:38 PM, Joel J. Adamson wrote:
>
>> So, what you're saying is that at any time that I need a particular
>> environment, I can resurrect it with a data structure, be that a
>
> Nope. Again, the environment is a data representation of the lexical
> context of some phrase in your program.
[...]
Okay, that I understand.
> If the phrase is a function definition
>
> ... (define (f x) ...) ... ;; in Scheme
> ... int f(int x) { ... } ... ;; in a C-ish syntax
>
> then the interpreter uses the current environment to build another
> data structure: the closure.
So the closure is a construction of the interpreter. This is making
more sense now.
> The closure is a data representation that is just a struct with two
>fields:
>
> -- one field that points to the environment of the function definition
> -- another field that points to the code of the function definition
How concrete are we talkin' here? Are you saying the MzScheme
interpreter builds a struct in the sense that I could manipulate it
with struct functions (if I knew what it was called)? I don't want to
know what it's called or manipulate it, but this helps me understand
what someone means when they say "I'd do this using closures."
Are we starting to get at the "What's so great about Lisp?" here?
> Time to read HtDP and PLAI now. -- Matthias
I read the first chapter of PLAI last night, and I'm really enjoying
it. I skimmed through much of HtDP, and found plenty of good
conceptual angles in it. Perhaps I'll go back and read some of the
later chapters. And you'll be happy to know I'm reading through the
Little Schemer for the second time.
One of the things I enjoy about Lisp programming books is that they
cover a variety of perspectives, motivations for studying programming
and levels of experience. I have plenty of programming experiences,
just not C++; everything I encountered when studying Python seemed to
be aimed at people who had studied C++ their entire lives.
Thanks for all your help --- this list is fantastic,
Joel
--
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA 02114
(617) 643-1432
(303) 880-3109
The information transmitted in this electronic communication is intended only for the person or entity to whom it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this information in error, please contact the Compliance HelpLine at 800-856-1983 and properly dispose of this information.