all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: Lexical and Dynamic Scope
Date: Fri, 25 Jul 2014 00:16:44 +0200	[thread overview]
Message-ID: <878unio10z.fsf@debian.uxu> (raw)
In-Reply-To: mailman.5948.1406191841.1147.help-gnu-emacs@gnu.org

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


  parent reply	other threads:[~2014-07-24 22:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.5712.1405800439.1147.help-gnu-emacs@gnu.org>
2014-07-20 19:47 ` Lexical and Dynamic Scope Emanuel Berg
2014-07-24  8:50   ` Aurélien Aptel
     [not found]   ` <mailman.5948.1406191841.1147.help-gnu-emacs@gnu.org>
2014-07-24 22:16     ` Emanuel Berg [this message]
2014-07-24 22:28       ` Stefan Monnier
     [not found]       ` <mailman.5974.1406240948.1147.help-gnu-emacs@gnu.org>
2014-07-24 22:44         ` Emanuel Berg
2014-07-19 18:12 run-with-timer does not display message Stefan Monnier
2014-07-19 20:06 ` Lexical and Dynamic Scope Robert Thorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878unio10z.fsf@debian.uxu \
    --to=embe8573@student.uu.se \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.