From: Eduardo Ochs <eduardoochs@gmail.com>
To: tomas@tuxteam.de
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Lexical vs. dynamic: small examples?
Date: Sat, 14 Aug 2021 13:00:34 -0300 [thread overview]
Message-ID: <CADs++6jrhKgLJhf9768Pvq1=rfkUmA=rkgBUy86gF-bbWPDEwg@mail.gmail.com> (raw)
In-Reply-To: <20210814073518.GC11671@tuxteam.de>
On Sat, 14 Aug 2021 at 04:35, <tomas@tuxteam.de> wrote:
>
> Hm. I have the feeling that it'll difficult to appreciate the
> differences between lexical and dynamic bindings whithin such
> short snippets. You don't have much room to build up a lexical
> environment worth its salt :-)
>
> The metaphor which, for me, did "click" was: lexical binding is
> a binding along "space", dynamic binding along "time".
Hi Tomas,
I forgot to explain some things about the style of that tutorial... I
thought that they would be obvious, but they're not.
The two programming languages that I use more are Elisp and Lua, and
Lua only has lexical binding... so I know how lexical binding works,
how to use it, and what are its advantages, but its exact semantics in
Lua only became clear to me when I learned 1) how to inspect all the
"local variables" of a running Lua function - in Lua this includes the
arguments that the function received, and 2) how some local variables
are "captured" to become upvales. This is explained in pages 8 and 9
here:
https://web.tecgraf.puc-rio.br/~lhf/ftp/doc/jucs05.pdf#page=9
My main intent with eev since the beginning (in the mid-90s) has
always been to create my own "executable notes" and share them, and to
make other people create and share their executable notes too... there
seemed to be some kind of taboo against that at that time: people
shared textual explanations happily but hesitated an almost infinite
number of times before sharing runnable snippets, and I was tired of
spending hours every time undoing their translations from snippets to
textual explanations to reconstruct the runnable snippets that they
didn't want to share...
Two days ago someone on IRC told me that the documentation of Common
Lisp has great explanations of how lexical bindings works on CL, and
that lots of it applied to lexical binding in Emacs too. I forgot to
ask for links - when I get them I will add them to my tutorial,
probably just preceding them by a "See:", because I am trying to keep
my own textual explanations very short.
This page
http://www.gnu.org/software/emacs/manual/html_node/elisp/Closures.html
(find-elnode "Closures")
says:
However, the fact that the internal structure of a closure is
exposed to the rest of the Lisp world is considered an internal
implementation detail. For this reason, we recommend against
directly examining or altering the structure of closure objects.
but for me, and for many people that I know, the easiest way to
understand a specification that can be implemented in many ways is to
study the specification AND one implementation of it. Snippets that
show the "internal implementation details" of the current
implementation of lexical binding in Emacs are hard to find, so I'm
writing them myself - and asking for help. Eev has several kinds of
hyperlinks to source code, like this one,
;; (find-efunction 'defvar "declared_special")
that finds the definition of defvar - a DEFUN ("defvar", ...) - in the
C source of Emacs and searches for string "declared_special" in it,
and I am using them in my notes and tutorials to point the primary
source of information about the implementation details - the source
code! - instead of writing my own textual explanations.
So, that's why I was so happy when I found the getter/setter example
that is here:
http://angg.twu.net/eev-intros/find-lexical-intro.html#3
(find-lexical-intro "3. `get/set'")
https://0x0.st/-JRW.bin
(find-wget-elisp "https://0x0.st/-JRW.bin")
It has some code that was quite mysterious to me until a few days ago
- the (defun get/set0 ...), that buils two closures that share the
same lexical environment - and it shows how that code gets translated
to lower-level elisp code that I could understand.
Cheers,
Eduardo Ochs
http://angg.twu.net/#eev
http://angg.twu.net/eev-intros/find-elisp-intro.html
http://angg.twu.net/eev-intros/find-lexical-intro.html
next prev parent reply other threads:[~2021-08-14 16:00 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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='CADs++6jrhKgLJhf9768Pvq1=rfkUmA=rkgBUy86gF-bbWPDEwg@mail.gmail.com' \
--to=eduardoochs@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=tomas@tuxteam.de \
/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).