From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eduardo Ochs Newsgroups: gmane.emacs.help Subject: Re: Lexical vs. dynamic: small examples? Date: Sat, 14 Aug 2021 13:00:34 -0300 Message-ID: References: <20210814073518.GC11671@tuxteam.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22060"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: tomas@tuxteam.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 14 18:02:36 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEw7I-0005Yf-Ca for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 14 Aug 2021 18:02:36 +0200 Original-Received: from localhost ([::1]:54764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEw7G-00012J-1s for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 14 Aug 2021 12:02:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEw5b-0007DK-3E for help-gnu-emacs@gnu.org; Sat, 14 Aug 2021 12:00:52 -0400 Original-Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:52805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mEw5Y-0005zs-PC for help-gnu-emacs@gnu.org; Sat, 14 Aug 2021 12:00:50 -0400 Original-Received: by mail-pj1-x1036.google.com with SMTP id nt11so19867366pjb.2 for ; Sat, 14 Aug 2021 09:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3GkXmAEIifIW+ZdkkyXyYEGoI6/3rlJ6X430eMLryag=; b=MKUn43rL3k7/hWr/maFH1gufRU6RXxzIlNcpFE3y104FUKXtbI4GR6dyqWNM/vYAuN t6OEI+isaZuTlrsW3PPsr0iKshUWLlRsDVTVqNPl1wa4hU7vBYeQEXv+4p5TjvSXFw61 rpf3f2OIOKo5d0lOcJmvrCZdJYJmzf/YLtQcvWNFbGunpzMNFySlEbFpHbsgpY5fqmIk rWMNcl5OwhEfnfqreUn4kr4TvyFE1nj5Qu2/ucS/fpFbmwL47Og79kyoI7pzBUoWOLqo lMkNWGfttIeqc/WtynaAyf2k1Nwd0OYa6Cll1bJPlWKPTKQG9F75A2Zcr//NIEc10PnZ 6GSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3GkXmAEIifIW+ZdkkyXyYEGoI6/3rlJ6X430eMLryag=; b=A6yc7HtHMJzbB78E1qxO1vOnd8PTJ5BI50TFv1beT5JMy69x4s6gvJBMibLDyAmV8j CeoY+M5quWA0EFe6bUb0s2ImtThhdXPwl8KyHM4HhJkFsEVq7T/wwIxCq0sAyOJXMGA/ d7x05A75QlKIawIXIOS+GFgcehMow72oJ0dlMYRmiMjpqvjyF6J4CepWORaj2O/bjJzO Vpv6tlrKWjz+jPLDRuVBx51+Q8mOtfXE2AMwLmWkSsIs0oAzqfzzZxELoooPFNdEzYQP sHaW7of3PW6NKHqYMkLsSv5FpoLtVw1oDlkmH8w0o+slSpTTyy5QebT8Yb6COqrjqG6p 7blA== X-Gm-Message-State: AOAM532vN5Xe/KwcruUrhPTrpXRhJPvz9+wAWOUXM/BZpmLDIo5Vex6d jfkY6VWPOIrTJBoglNQ0WjNq+q252dIfr+ixS1GR4KU7rzXadg== X-Google-Smtp-Source: ABdhPJzJ8xD5esqznw2B6kriW36h2KLi6dkHQNcdMn5LtM1cqFuOhIfinmbubqu65+Rn/1tNI3qNyxPINrnEgLKO76s= X-Received: by 2002:a17:90b:1989:: with SMTP id mv9mr7787124pjb.100.1628956846867; Sat, 14 Aug 2021 09:00:46 -0700 (PDT) In-Reply-To: <20210814073518.GC11671@tuxteam.de> Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=eduardoochs@gmail.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:132538 Archived-At: On Sat, 14 Aug 2021 at 04:35, 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