From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Lexical binding doesn't seem to be faster? Date: Sat, 9 Mar 2019 09:21:29 +0100 Message-ID: <20190309082129.GA31605@tuxteam.de> References: <20190308083055.GA20901@tuxteam.de> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="HcAYCG3uE/tztfnV" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="223741"; mail-complaints-to="usenet@blaine.gmane.org" 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.org@gnu.org Sat Mar 09 09:21:56 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h2XEw-000w5N-E0 for geh-help-gnu-emacs@m.gmane.org; Sat, 09 Mar 2019 09:21:54 +0100 Original-Received: from localhost ([127.0.0.1]:55829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2XEv-0008St-Df for geh-help-gnu-emacs@m.gmane.org; Sat, 09 Mar 2019 03:21:53 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:54365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2XEd-0008S1-Lm for help-gnu-emacs@gnu.org; Sat, 09 Mar 2019 03:21:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2XEb-0007Ri-6e for help-gnu-emacs@gnu.org; Sat, 09 Mar 2019 03:21:35 -0500 Original-Received: from mail.tuxteam.de ([5.199.139.25]:46361) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h2XEa-0007Pu-MQ for help-gnu-emacs@gnu.org; Sat, 09 Mar 2019 03:21:33 -0500 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=ftH5qBF3A1uRkz2YuTtoRHt0xJmXr6W9uHEhMPa44Tg=; b=T5e2ZYS8Ho4ch8nrCf5gQa+5LFF8xUz33Ec12118W1grKVy7CFK+INo8fyKN9+rbPWZD2lRHK0oayp4dLjrBEE1e9emxKM+NkemMY7l02Aw39omLoSmKMx+fbCEvDi5Js69lfSJO4Oa47YB4Qd0rSPG5JNrMkG/mP2WpDWrFpFQm7Cpf8xEsxluVvYA2KfFg1zIf9vMEv4jdXOCi/go2CvmVJr5D6kJPmSSVl3yFYgA1VO2CEMLLb/6Q8fM8eNrE/F6fOL9EebRU6cWMPECPR2cJkjCYSiH8Ruq3M8UoeVMj0SQnBWjyxdjEhqwkuC6mmxVSyEZM04zE91QGKBnMMA==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1h2XEX-0008K0-Pv for help-gnu-emacs@gnu.org; Sat, 09 Mar 2019 09:21:29 +0100 Content-Disposition: inline In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 5.199.139.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:119591 Archived-At: --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Mar 08, 2019 at 08:53:32AM -0500, Stefan Monnier wrote: [free variables, lexical vs. dynamic bindings and differences in behaviour] > Actually, in most such cases the code behaves identically in the end, > but it gets there in a different way (so yes, in some cases it does > behave differently). >=20 > E.g. >=20 > (let ((buf (current-buffer))) > [...] > (with-temp-buffer > (mapcar (lambda (x) > (with-current-buffer buf ...)) > ...)) > [...]) > =20 > The end result will most likely be the same regardless which binding > style is used, but the way to find the value of `buf` from within the > lambda is different in the two cases. >=20 > The difference becomes apparent if you do >=20 > (advice-add 'mapcar :around > (lambda (&rest orig-call) > (let ((buf 42)) (apply orig-call)))) > =20 > since in this case dynamic-binding will cause your `with-current-buffer` > to try and use buffer 42 and signal an error (because of the name > conflict, aka "variable capture"), whereas lexical-binding > will be unaffected. Thanks for the nice example. In a way it is somewhat surprising how "similarly" lexical and dynamic binding tend to behave in general, but that is, I think, due to how we tend to structure code, avoiding variables whose "resolution" lies "far away". And your example illustrates that the differences manifest themselves most with constructs which upset the "dynamic flow" of the code, i.e. some kind of callback (which, in a very handwavy way, advice is a kind of). I.e. I'm "here" and tell the code "there" to run my own snippet "here" in its context "there". Or something. Cheers -- t --HcAYCG3uE/tztfnV Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlyDd4kACgkQBcgs9XrR2karqACfSXAXlFNhPxN5LJJ2lumda6vI 8U4AnRVt8N/Dbtrpfbpt+91U4y4XKJCU =+Xac -----END PGP SIGNATURE----- --HcAYCG3uE/tztfnV--