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

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

Re: Lexical and Dynamic Scope


From: Emanuel Berg
Subject: Re: Lexical and Dynamic Scope
Date: Fri, 25 Jul 2014 00:16:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Aurélien Aptel <aurelien.aptel+emacs@gmail.com> writes:

> In dynamic scoping, each time you nest a let binding
> to same symbol you add to this variable stack. When
> you take the value of a symbol the value comes from
> the top of the stack of this symbol.

The code you sent is somewhat unclear. When the
(presumed) programmer writes `my-a', it is somewhat
the assumption that what is intended is the global
variable, because there isn't any other `a' around. (To
use global variables and return them from functions at
that - but OK, it is an example to show the principle,
I get that.)

On the other hand, in the `let' clauses, it is far from
clear that `my-a' will even be affected as in those
clauses, there isn't even an `a' mentioned.

I actually think that `my-a' shouldn't be affected!
When I use `let', it is just to make the code easy to
write, read, and change, and any code invoked from the
`let' list that happens to refer to some entity with
the same name shouldn't be affected.

I never use `defvar', but sometimes `setq'.

I use `setq' in most cases when two functions need to
work on some shared file or buffer name, and I want
that set in one place, where I to change it - it is not
part of the interface to other functions or Emacs in
general, so I would declare it restricted to those two
defuns did I know a practical way.

I use `let' and function parameters and I expect those
to always be prioritized before any global or otherwise
more distant entities with the same names. If the
`let's are nested, or if they share the same name as
one of the parameters - both situations I consider
confusing and haven't done ever, I think - but OK, in
those cases I expect the most recent mention (in the
code) to hold. I don't expect `let' to affect any other
code than the code in the `let' list itself, where
references to the bound name will be replaced for the
corresponding data.

The only time I had problems with this is when I setup
lambdas using bindings from `let' and function
parameters. Apparently the lambdas disassociated
themselves from those bindings, and instead looked for
global variables. OK, I know that now so that won't
happen again.

-- 
underground experts united


reply via email to

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