unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: "help-gnu-emacs@gnu.org List" <help-gnu-emacs@gnu.org>
Subject: Re: Declaring a local dynamic variable?
Date: Fri, 27 Sep 2013 20:48:34 +0200	[thread overview]
Message-ID: <5245D302.2010907@easy-emacs.de> (raw)
In-Reply-To: <barmar-DB4749.10311927092013@news.eternal-september.org>

Am 27.09.2013 16:31, schrieb Barry Margolin:
> In article <mailman.2982.1380275511.10748.help-gnu-emacs@gnu.org>,
>   Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:
>
>> Am 25.09.2013 20:53, schrieb Stefan Monnier:
>>>>>> So in essence Emacs doesn't really have local dynamic variables?
>>>>> Dynamic scoping is inherently global, whether in Elisp or in any other
>>>>> language.
>>>
>>>> Not in Common Lisp.
>>>
>>>> (defun d1 ()
>>>>     (let ((var 1))
>>>>       (declare (special var))
>>>>       (l1)))
>>>
>>>> (defun l1 ()
>>>>     (let ((var 2))
>>>>       (print var)
>>>>       (d2)))
>>>
>>>> (defun d2 ()
>>>>     (declare (special var))
>>>>     (print var))
>>>
>>>> D1 and D2 use the dynamic variable VAR, L1 uses the lexical variable VAR.
>>>
>>> Same in Elisp.  But if d1 and d2 are in two separate packages that know
>>> nothing about each other but who happen to call each other through some
>>> potentially twisted sequence of calls, they will still interfere,
>>> because there's only (globally) one dynamic variable by that name.
>>>
>>
>> Now if two separate packages define a lexical var with the very same, is such
>> a confusion excluded?
>
> Yes. By definition, lexical variables are only visible in the lexical
> contour, not in other functions.

I'm afraid it's not about definition, as let-bound variables should not be inherently global,

Let's memorize Stefan's remark as a starting-point to work-on:

" But if d1 and d2 are in two separate packages that know
nothing about each other but who happen to call each other through some
potentially twisted sequence of calls, they will still interfere,
because there's only (globally) one dynamic variable by that name."

Would like to see such a twisted sequence and what makes it's different from a common bug.

>
> The exception is if a macro expands into code that binds the variable:
>
> (defmacro pkg1-m (&body b)
>    `(let ((var 'm))
>       ,@b))
>
> (defun pkg2-f ()
>    (let ((var 'f))
>      (pkg1-m
>        (print var))))
>
> (pkg2-f) will print "m" rather than "f".

Mmm, maybe I don't understand, but that wouldn't surprise me, because pkg1-m re-binds it(?)


>
> This is generally referred to as the "hygiene" problem in macros. It's
> why macros should use gensym to create the local variables used in the
> expansion, or take the variable as a parameter.  Dialects like Scheme
> have built-in mechanisms to create hygienic macros.
>




  reply	other threads:[~2013-09-27 18:48 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-20  9:52 Declaring a local dynamic variable? Joost Kremers
2013-09-20 12:30 ` Stefan Monnier
2013-09-20 14:54   ` Andreas Röhler
     [not found]   ` <mailman.2569.1379688787.10748.help-gnu-emacs@gnu.org>
2013-09-20 15:10     ` Barry Margolin
2013-09-20 16:34       ` Andreas Röhler
     [not found]       ` <mailman.2578.1379694764.10748.help-gnu-emacs@gnu.org>
2013-09-20 20:59         ` Barry Margolin
2013-09-21  5:49           ` Andreas Röhler
2013-09-23 16:19           ` Joost Kremers
     [not found]           ` <mailman.2622.1379742443.10748.help-gnu-emacs@gnu.org>
2013-09-21 11:31             ` Barry Margolin
2013-09-21 13:32               ` Andreas Röhler
     [not found]               ` <mailman.2638.1379770251.10748.help-gnu-emacs@gnu.org>
2013-09-22  3:49                 ` Barry Margolin
2013-09-23 16:26             ` Joost Kremers
2013-09-23 21:17               ` Barry Margolin
2013-09-23 22:14                 ` Joost Kremers
2013-09-24  0:03                   ` Barry Margolin
2013-09-25  8:58                     ` Joost Kremers
2013-09-22 17:11 ` Pascal J. Bourguignon
2013-09-23 16:17   ` Joost Kremers
2013-09-24 21:40   ` Stefan Monnier
2013-11-02 23:56   ` WJ
2013-11-03  1:42   ` WJ
     [not found] ` <mailman.2566.1379680283.10748.help-gnu-emacs@gnu.org>
2013-09-23 16:11   ` Joost Kremers
2013-09-24 21:34     ` Stefan Monnier
2013-09-25  5:52       ` Andreas Röhler
2013-09-25  7:24         ` Stefan Monnier
2013-09-25  8:43       ` Joost Kremers
2013-09-25 12:26         ` Stefan Monnier
2013-10-12 16:54           ` Andreas Röhler
     [not found]           ` <mailman.3886.1381596756.10748.help-gnu-emacs@gnu.org>
2013-10-12 21:25             ` Kai Grossjohann
2013-10-13  8:12               ` Andreas Röhler
2013-10-13 13:37                 ` Stefan Monnier
2013-10-13 17:41                   ` Andreas Röhler
2013-10-13 19:56                     ` Kai Großjohann
     [not found]         ` <mailman.2843.1380112007.10748.help-gnu-emacs@gnu.org>
2013-09-25 15:46           ` Barry Margolin
2013-09-25 18:53             ` Stefan Monnier
2013-09-27  9:53               ` Andreas Röhler
2013-09-27 13:15                 ` Stefan Monnier
     [not found]               ` <mailman.2982.1380275511.10748.help-gnu-emacs@gnu.org>
2013-09-27 14:31                 ` Barry Margolin
2013-09-27 18:48                   ` Andreas Röhler [this message]
     [not found]                   ` <mailman.3016.1380307597.10748.help-gnu-emacs@gnu.org>
2013-09-27 20:18                     ` Pascal J. Bourguignon
2013-09-27 23:57                       ` Stefan Monnier
2013-09-28  6:20                       ` Andreas Röhler
2013-09-28  6:24                         ` W. Greenhouse
2013-09-28  6:50                           ` Andreas Röhler
2013-09-28  7:21                             ` W. Greenhouse
     [not found]             ` <mailman.2873.1380135245.10748.help-gnu-emacs@gnu.org>
2013-09-26  0:06               ` Barry Margolin

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=5245D302.2010907@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.de \
    --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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).