unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Lexical vs. dynamic: small examples?
@ 2021-08-14  3:34 Eduardo Ochs
  2021-08-14  3:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
                   ` (3 more replies)
  0 siblings, 4 replies; 61+ messages in thread
From: Eduardo Ochs @ 2021-08-14  3:34 UTC (permalink / raw)
  To: help-gnu-emacs

Hi list,

I am trying to write a section on lexical vs. dynamic binding for a
tutorial on Emacs Lisp, and I am looking for very short demos that
show how things work differently in dynamic and in lexical binding...

Right now what I have is this:

  http://angg.twu.net/eev-intros/find-lexical-intro.html
  (find-lexical-intro)

I have tried really hard to the make its section "0. How to use this",
that is at:

  http://angg.twu.net/eev-intros/find-lexical-intro.html#0
  (find-lexical-intro "0. How to use this")

both clear AND useful to people who do not use eev, and I think that
the big example in section 3,

  http://angg.twu.net/eev-intros/find-lexical-intro.html#3
  (find-lexical-intro "3. `get/set'")

is quite nice - especially because of its last part, that inspects two
different getter-setter pairs, shows that their lexical environments
are the cadrs of their closures, and shows that `geta' and `seta'
share the same lexical environment and that `getb' and `setb' share
another lexical environment...

My current knowledge of lexical binding stops there, though. Any
comments (or help) would be very welcome...

  Cheers,
    Eduardo Ochs
    http://angg.twu.net/#eev



^ permalink raw reply	[flat|nested] 61+ messages in thread
* Re: Lexical vs. dynamic: small examples?
@ 2022-01-09 17:40 Drew Adams
  2022-01-10 13:10 ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 61+ messages in thread
From: Drew Adams @ 2022-01-09 17:40 UTC (permalink / raw)
  To: Emanuel Berg, 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'

[-- Attachment #1: Type: text/plain, Size: 1776 bytes --]

> >> FWIW, I just wrote a tiny library, `dyna-show.el', that
> >> defines minor mode `dyna-show-mode', which highlights
> >> occurrences of "special" (aka dynamically
> >> scoped) variables.
> >>
> >> It just uses `special-variable-p', which is limited.
> >>
> >> From the attachment, you can see another limitation:
> >> occurrences of a function, e.g. `font-lock-mode', that has
> >> the same name as a dynamic variable are also highlighted.
> >
> > Thanks, it is very helpful for cosmetics of the code.
> 
> But here it also has a functional value. Or to be even more
> precise, the functional value is also what is appealing, since
> I think it started in that end.

tl;dr:
1. It can be useful.  2. It's not foolproof.
___

I guess you're referring to this (from the
`dyna-show.el' Commentary)?

 [I]f a function has the same name as a dynamic
 variable, then its occurrences are also
 highlighted, as if they were occurrences of
 the variable.

For example `font-lock-mode' is a variable as
well as a function.  Both kinds of occurrences
of that symbol are highlighted the same.

Whether this is considered a feature or a
limitation, the reason is that it requires no
analysis of the code (which would anyway be
problematic and limited) to determine how each
occurrence is used.  

The Commentary calls it out as a limitation.
And the sentence above comes right after this
additional caveat:

 The simple built-in test `special-variable-p'
 is used.  That test is not 100% reliable.  It
 doesn't respect vacuous `defvar' sexps, which
 declare a variable to be special in a given
 context, without assigning a value to the
 variable.  Instead, it uses `defvar',`defconst',
 and `defcustom' sexps with a value arg present.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 13769 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

end of thread, other threads:[~2022-01-10 13:10 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-14  3:34 Lexical vs. dynamic: small examples? Eduardo Ochs
2021-08-14  3:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-14  4:12   ` Eduardo Ochs
2021-08-14  7:35 ` tomas
2021-08-14 16:00   ` Eduardo Ochs
2021-08-14 19:41     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-14 20:42     ` tomas
2021-08-14 19:31   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-14 20:31     ` tomas
2021-08-14 21:26       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-14 21:29         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-14 13:35 ` [External] : " Drew Adams
2021-08-14 16:15   ` Eduardo Ochs
2021-08-14 19:00 ` Gregory Heytings
2021-08-14 20:16   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-14 20:23     ` Gregory Heytings
2021-08-14 21:05       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-14 21:13         ` tomas
2021-08-14 21:28           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-14 20:41   ` tomas
2021-08-15  0:29   ` [External] : " Drew Adams
2021-08-15  0:52     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15  1:04     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15  1:18     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15  4:44       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15  5:02         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 15:49         ` Drew Adams
2021-08-15 18:49           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 21:55             ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-08-15 22:04               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 21:57             ` Drew Adams
2021-08-15 22:20               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 22:54                 ` Drew Adams
2021-08-15 23:16               ` Drew Adams
2022-01-09  7:08                 ` Jean Louis
2022-01-09 15:03                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 23:42               ` Arthur Miller
2021-08-15 22:02             ` Lars Ingebrigtsen
2021-08-15 22:22               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 22:44                 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-08-21  3:38                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-24  2:08                     ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-08-25 23:34                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-25 23:40                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-26  0:10                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-26  0:44                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-26 17:01                               ` FW: " Drew Adams
2021-08-26 23:05                                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-25 23:46                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-25 23:47                         ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-08-26  0:57                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-28  1:36                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-28  1:41                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 22:44               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 22:58                 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-08-15 23:13                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 23:56                     ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-08-16  0:43                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-15 15:42       ` FW: " Drew Adams
  -- strict thread matches above, loose matches on Subject: below --
2022-01-09 17:40 Drew Adams
2022-01-10 13:10 ` Emanuel Berg via Users list for the GNU Emacs text editor

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).