[plt-scheme] Re: applying set! on the contents of a variable
On Sep 30, Majorinc, Kazimir wrote:
> We can at least make local namespaces. Few
> macros good only to show what's possible. Real usage would
> require lot of quotes and evals.
Lots of quotes mean that you should learn how to use quasiquotes, or
even better -- `define-syntax' and `syntax-rules'. These will get you
much smaller and more understandable code.
Lots of `eval's are an indication that your solution is not great.
> And really, why it is not design decision that eval supports local
> variables? What is the reasoning behind that limitation of, I
> believe, the most powerful feature or Scheme?
Try this:
(compile '(define (foo x)
(let ([my-local 123]) (+ my-local my-local))))
(compile '(define (foo y)
(let ([other-local 123]) (+ other-local other-local))))
This will show you what mzscheme compiles the two definitions to. It
will be some random indecipherable binary junk, but the important
point is that the two expressions compile to exactly the same code.
This means that the local names are irrelevant. The only things that
are left are global names, which must be referred to by their name (so
you will see a "foo" in there).
More than that, try this:
(compile '(define (foo x) (+ 123 123)))
and you'll see that it's it compiles to the same code too -- which
shows that mzscheme just got rid of the redundant local binding in the
first two forms -- so not only is the name not there, the binding
itself is not there. You could not do any of these things if you
needed an `eval' that knows about lexical scope, and this is just the
tip. The resulting language would be *much* slower.
Some languages fall into this trap and then have hard time
recovering. IIRC, you can get a hash-table that represents the
current scope in Python -- but you cannot use it to change bindings.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!