* Re: How must we teach lexical scope?
@ 2007-03-29 3:45 oleg
0 siblings, 0 replies; 2+ messages in thread
From: oleg @ 2007-03-29 3:45 UTC (permalink / raw)
To: loup.vaillant, caml-list
Loup Vaillant wrote:
> Personally, I think environments are about the implementation of
> lexical scope, not its specifications.
I agree. A language system that eagerly performs substitutions
inherent in the beta-rule needs no environments. An environment, which
is a list of pending substitutions, is merely an optimization. A quite
good optimization though. This is discussed in an article
http://okmij.org/ftp/Scheme/misc.html#closure-misconceptions
Regarding free variables: some of the multi-staged languages,
including MetaOCaml, can literally manipulate code with `free
variables'. For example,
let bar u = print_endline "here"; .<.~u + 1>. in
.<fun x -> .~(bar .<x+3>.)>.;;
Evaluating this code prints the string "here" and returns a code
value, which can be printed as .<fun x_1 -> ((x_1 + 3) + 1)>.
We note that the function bar received a piece of code .<x+3>.
containing a free variable 'x' and incorporated that piece of code
in the larger code. All while the binding for "x", "fun x -> ..." will
be evaluated only in the future.
^ permalink raw reply [flat|nested] 2+ messages in thread
* How must we teach lexical scope?
@ 2007-03-28 7:59 Loup Vaillant
0 siblings, 0 replies; 2+ messages in thread
From: Loup Vaillant @ 2007-03-28 7:59 UTC (permalink / raw)
To: caml-list
My brother is currently learning Camllight at the Toulouse 3
university, France. Five years ago, I followed the same course.
I don't understand the way were are taught lexical scope. Our
professors used "environments", where free variable would suffice.
(An environment is the set of defined values at a given time. The
environment of a value is the environment of when this value is
defined.)
-> They talk about closures, even in the case of pure functional
style, even in the absence of free variable (except the built in
constructions, such as '+').
-> They take hours and hours of boring an silly looking exercises
about environment, so we can understand how important environments
are.(we even had to learn a specific syntax to talk about them).
-> The promised power of the language is completely overlooked. Even
the crippled Pascal on my calculator looked more powerful.
Luckily, I had later a professor, who showed us the real power of
Caml. He didn't talked about environments.
So here are a few questions:
-> Is lexical scope that important when learning pure functional programming?
-> Are environments helpful (even the slightest bit) when teaching
lexical scope?
-> Where does this idea come from? I have not read a single book, as
single article nor blog talking about environments.
-> How can we teach lexical scope? Is there a simple solution, the
kind of a first year student can understand in less than an hour?
Thanks,
Loup
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-03-29 3:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-29 3:45 How must we teach lexical scope? oleg
-- strict thread matches above, loose matches on Subject: below --
2007-03-28 7:59 Loup Vaillant
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox