Browse thread
Re: Redefinition doesn't work
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Michel Mauny <mauny@c...> |
| Subject: | Re: Redefinition doesn't work |
I don't want to spray gasoline on what looks like the beginning of a
flame war, but the `dynamic' behavior of Scheme variables shouldn't be
confused with dynamic scoping.
Pierre Weis wrote/écrivait (Nov 03 2000, 05:56PM +0100):
> Scheme has lexical scoping <EM>locally</EM>. It has dynamic binding
> globally,
> I find in the R5RS, a clear distinction between top level
> definitions that are said to be equivalent to assigments
That's because undefined identifiers are considered to be bound to
global locations. Therefore, a global definition is considered as an
assignment to such a location. This is where the difference comes
from.
To be sure that Scheme uses lexical binding for both global and local
identifiers, consider this simple example:
; -----------
(define (f x) (+ (g x) 1))
(f 1) ; => Error: g is undefined
(let ((g (lambda (z) z)))
(f 1)) ; => Error: g is still undefined, although it's avaliable
; from the dynamic env
(define (g x) x)
(f 1) ; => 2
; -----------
Under dynamic scoping, the second call (f 1) would succeed, since g is
available in the dynamic context. This is how ynamic Lisp would
behave.
In Scheme, when f is defined, g is lexically bound to a location. That
location is assigned when g gets defined (or redefined).
-- Michel
No, I'm not here.