From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Lexical vs. dynamic: small examples? Date: Sat, 14 Aug 2021 09:35:18 +0200 Message-ID: <20210814073518.GC11671@tuxteam.de> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="8X7/QrJGcKSMr1RN" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15479"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.5.21 (2010-09-15) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 14 09:35:53 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 1mEoCv-0003ma-7x for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 14 Aug 2021 09:35:53 +0200 Original-Received: from localhost ([::1]:45638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEoCt-0001Tt-LO for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 14 Aug 2021 03:35:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEoCS-0001TP-1F for help-gnu-emacs@gnu.org; Sat, 14 Aug 2021 03:35:24 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:35777) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1mEoCO-0001W3-MG for help-gnu-emacs@gnu.org; Sat, 14 Aug 2021 03:35:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:To:Date; bh=OUnmf/o+ndSLSOWdc7SQpO931UjgXnrb908FMK0R6pM=; b=CKFGTmdOMlKma4FqJtza8Cr1QZQh3ioZx6kTBB5rRq6LrK2/cNq09KNT3ZChtEsEaj+1m/EJaDO6PfqrnpFQ3ibXDwP/opuRRs5mYZ2Ery9e0j7EWA3q/nQkqDnGzvLO+rQbLWtr9PCnZoR5PQXqvLmitVU2uPRei20YreaUTO4rgLiO8WMq83hmkV5OAycxa65spKplrc28h56NS+OjljJnXxCL9iiGVoLzCF2AlhI20kP+m2bei+y+Fj3geX7GpahnJuG6W8QWhBmyOYDhwpbv7ENhADVDNbl0QPtFDj5LBPwM1zQ4+jCoHPbCgV+whwN+pC9dewmtcNn5KDljyQ==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1mEoCM-0003p6-Ap for help-gnu-emacs@gnu.org; Sat, 14 Aug 2021 09:35:18 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de 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, 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:132535 Archived-At: --8X7/QrJGcKSMr1RN Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Aug 14, 2021 at 12:34:31AM -0300, Eduardo Ochs wrote: > Hi list, >=20 > 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... >=20 > Right now what I have is this: >=20 > http://angg.twu.net/eev-intros/find-lexical-intro.html > (find-lexical-intro) 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". Usually you want both (and civilised languages, like CL, Scheme, Perl [1] and, of course, Emacs Lisp, the most civilised of all) do offer facilities for both. The easiest default, though (for compilers and for users alike) is lexical binding. Especially if you use other people's code in yours. Imagine that library `setq'-ing xyzzy "down there", although xyzzy happens to be an important variable in your missile-control program (to reuse an already tired analogy ;-) Of course, civilised library providers wouldn't do that, they would make sure `xyzzy' is let-bound before `setq'-ing anything. If the dynamic state doesn't do uncommon things and only walks the stack "up and down", then it's their variable to `setq', no matter whether dynamically or lexically. The corollary is that for most civilised code, there is no difference whether it is interpreted in a lexical or dynamic scoping regime. Stefan, who has taken up the Herculean task of going through the existing Emacs Lisp code to convert it to lexical sure has a lot of interesting things to say about that :-) Cheers [1] Perl originally had only lexical scope, like any decent shell always had. It was with Perl5 (about 1994) that it acquired lexical scope (called "my" in Perl-land) as the recommended variable localisation strategy. - t --8X7/QrJGcKSMr1RN Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAmEXcjYACgkQBcgs9XrR2kaY7gCfXsJ0oSWUR421GZc19Q80RCh5 rdoAnjwnZEH+uLDuT0NE5vaNJTmETacE =OZo+ -----END PGP SIGNATURE----- --8X7/QrJGcKSMr1RN--