Re: flet vars



In article <87aafhbr2g.fsf@xxxxxxxxxxxxxxx>,
Tim X <timx@xxxxxxxxxxxxxxx> wrote:

TheFlyingDutchman <zzbbaadd@xxxxxxx> writes:


Let's take a look at how (let) works:

(defvar a 10)
(defun foo () (setq a -10))
(let ((a 20)) (foo) (print a) ) => -10


And you defend that behavior? Amazing.


I thought I understood some of your 'issues', but now I'm confused? The
above example makes perfect sense to me. Which 'a' were you expecting to
be modified when you call foo within the scope of your let? I'm assuming
you had expected the special (dynamic in your terminology?) to be set to
-10 and for the lexical binding to remain at 20? If that was the
behavior you wanted, isn't that what declare special etc is for?

I must be missing something as the example seems fine to me and
perfectly defensible.

Tim

Suppose I want to make a lexical closure. I type this:

(let ((v 0))
(lambda () (incf v)))

But that may or may not give me a lexical closure depending on whether
or not at some previous point in this current session someone has typed
(defvar v ...) or some such thing. This is why the *earmuffs*
convention was developed, but any time you have to have a rule like that
it's an indication of a poor design. If all special variables should
have earmuffs, why not build that into the language spec?

The answer is that DEFVAR works the way it does not because it's a good
design, but because part of CL's mission statement was to unify
dynamically and lexically scoped lisps. But no one uses dynamically
scoped Lisps any more, so we are saddled with a bad design that was put
in place to satisfy a requirement that no one cares about any more.

rg
.



Relevant Pages

  • Re: flet vars
    ... But that may or may not give me a lexical closure depending on whether ... it's an indication of a poor design. ... The answer is that DEFVAR works the way it does not because it's a good ... dynamically and lexically scoped lisps. ...
    (comp.lang.lisp)
  • Re: flet vars
    ... But that may or may not give me a lexical closure depending on whether ... (defvar v ...) ... considered to enforce the naming convention for special variables, ... ISLISP indeed has a better design for special variables, ...
    (comp.lang.lisp)