all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Aurélien Aptel" <aurelien.aptel+emacs@gmail.com>
To: Emanuel Berg <embe8573@student.uu.se>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: Lexical and Dynamic Scope
Date: Thu, 24 Jul 2014 10:50:35 +0200	[thread overview]
Message-ID: <CA+5B0FPo63V8jrGwFhMasC9DM=rNO0c0Jd_5wsdjB-gUJxFWBQ@mail.gmail.com> (raw)
In-Reply-To: <87ha2bstgt.fsf@debian.uxu>

On Sun, Jul 20, 2014 at 9:47 PM, Emanuel Berg <embe8573@student.uu.se> wrote:
> But: is the stack of names global? Howcome all the Lisp
> don't get crazy from other Lisp changing "its"
> variables? But come to think of it, I very seldom use
> variables - I use `let's, and perhaps that is both a
> shield from interference and doesn't change the global
> name stack?

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.

    (defvar a 1)
    (defun my-a ()
      "Return current value of a (top top the stack)"
      a)

    (my-a)
    => 1

    (let ((a 2)) ;; push 2 in the `a' stack
      ;; we usually say: a is shadowed in this scope
      (my-a))
    => 2

    ;; at the end of let scope, 2 is popped from the stack
    (my-a)
    => 1

    (list
     (my-a)

     (let ((a 2))
       (my-a))

     (let ((a 3))
       (let ((a 4))
         (my-a)))

     (my-a))
    => (1 2 4 1)



  reply	other threads:[~2014-07-24  8:50 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 [this message]
     [not found]   ` <mailman.5948.1406191841.1147.help-gnu-emacs@gnu.org>
2014-07-24 22:16     ` Emanuel Berg
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='CA+5B0FPo63V8jrGwFhMasC9DM=rNO0c0Jd_5wsdjB-gUJxFWBQ@mail.gmail.com' \
    --to=aurelien.aptel+emacs@gmail.com \
    --cc=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.