help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Differences between Elisp and Lisp


From: Phillip Lord
Subject: Re: Differences between Elisp and Lisp
Date: 29 Apr 2003 16:56:32 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2.93

>>>>> "Kent" == Kent M Pitman <pitman@world.std.com> writes:

  Kent> Thomas Link <samul@web.de> writes:

  >> > I thought that CL already implemented lexical binding? At least
  >> >within a let form (or "lexical-let").
  >> I guess it's faking lexical binding by replacing variable names
  >> with gensyms. This makes it pseudo-lexical but not more
  >> efficient.

  Kent> In addition to having questionable efficiency issues, such a
  Kent> strategy also eliminates the one primary reason that more than
  Kent> anything justifies lexical scoping--the ability to know 'just
  Kent> by looking' that no other uses of the variable exist and that
  Kent> it's ok to optimize. 

Perhaps I am confusing things here, but I always assumed that the
problem with dynamic binding is that it makes odd things happen.

So take...

(defvar x 1)

(defun test()
  (let ((x 10))
    (test2)
    (message "test: %s" x)))

(defun test2()
  (setq x 20))

(test)

x


Eval'ing (test) gives "test: 20", and x gives 1.
If you change the let to lexical-let you get
"test:10" and "20". This seems much more intuitive to me. Of course
its useful to be able to "subvert" the setq in test2 to not work on
the main defvar defined x, and I've used this occasionally. But in
general its likely to result in program errors, as the test function
needs to know that none of the functions it use a variable called x.

Optimisation might be an issue as well of course, but processors are
fast these days! Its nice, but not essential. 


Cheers

Phil


reply via email to

[Prev in Thread] Current Thread [Next in Thread]