home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.perl:7033 comp.lang.scheme:2605 comp.lang.tcl:1864
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!news.cs.columbia.edu!mail
- Newsgroups: comp.lang.perl,comp.lang.scheme,comp.lang.tcl
- Date: Wed, 18 Nov 92 00:09:50 EST
- From: thayer@cs.columbia.edu (Charles Thayer)
- Message-ID: <9211180509.AA04035@cs.columbia.edu>
- Subject: Re: Closures, Object-Oriented Equivalence, New version of Perl and TCL
- References: <9211110521.AA01343@cs.columbia.edu>
- Lines: 49
-
- > For example, in Scheme, a 'define' saves the current environment and
- > leaves the ability to reach the enclosing (dynamic) environment:
-
- That's not quite right. DEFINE does not save the current environment.
- It only binds a value to a variable.
-
- I was not refering to the scheme meaning of `environment'. I meant
- the entire set of visible bindings. In scheme the `environment' only
- holds the most immediate visible bindings.
-
- I would also say that "define" creates a new binding in the current
- environment, as opposed to set! which changes the value bound to a
- variable in that variable's appropriate environment.
-
- When a closure is created with LAMBDA it effectively "remembers" the
- current environment. The environment doesn't always need to be saved,
- though. We only need to save the value of free variables within the
- body of the LAMBDA expression. If there are no free variables, we
- don't need to keep any extra environment around.
-
- [We do need to keep around a pointer to our parent environment, but
- we digress on implementation]
-
- :) Which brings up an interesting point in mit-scheme:
-
- (begin
- (define a "moo")
- (define (foo)
- (display a)
- (define a "bar")
- )
- (foo))
-
- => Unassigned variable a
-
- Astute PERL users will notice that there are similar holes in the
- implementation of the exact same thing with respect to the main
- package :) which I find ironic.
-
- /charles
- PS. It's also amusing to note that this is not a problem in languages
- with a lasier mode of evaluation including TCL and SIOD. Mileage
- varies.
-
- PPS. Disclaimer: This is not meant to imply that this is a bug or
- a feature, just a fact to be aware of.
-
- ==============================================================================
- Charles Thayer, Columbia University, Dept. CS, Tech-staff... my words only.
-