Browse thread
How must we teach lexical scope?
[
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: | 2007-03-29 (08:17) |
From: | Loup Vaillant <loup.vaillant@g...> |
Subject: | Re: [Caml-list] How must we teach lexical scope? |
2007/3/28, ls-ocaml-developer-2006@m-e-leypold.de <ls-ocaml-developer-2006@m-e-leypold.de>: > But perhaps I understand your problem better now: The difference > you're wanting to make is the substitution of symbols by values at > definition time vs. at evaluation time (I hope it is clear what I want > to say). Exactly. > But you'll have to explain substitution at evaluation time > anyway (when a function is called and the formal parameters are > bound). I don't understand what your attempt to avoid to talk about an > environment (from which a comes in the example above) will buy you. Substitution at definition time is how I naturally thought of it. That is, the definition: # f x = a + x;; was automatically replaced by: # f x = 3 + x;; in my head, so there were no more need for any environment. However, I must admit such a way of thinking has its limits: as long as the substitution is simple, that is easy. When a free variable is some complicated piece of data (or even code), one (I) must switch to an environment representation. In that case, the environment I think about is only the set of free variables actually used by the function. The environments our professors talked about included all values, including the useless ones. I thought it was unnecessary, but I see the trade-of, now: their process is quite long (not to mention the syntactic burden of describing each environment) but it is systematic, and simple. Because it is, it looks silly. I don't like environments, but you convinced me I haven't came up with a better solution. Regards, Loup