From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: tomas@tuxteam.de Newsgroups: gmane.emacs.help Subject: Re: Closures - do you understand them well? Date: Mon, 12 Dec 2022 06:16:30 +0100 Message-ID: References: <87h6y5pt8k.fsf@web.de> <87bkodpqnk.fsf@web.de> <87k030tlfh.fsf@web.de> <87ilike1l8.fsf@gnu.org> <87cz8suv92.fsf@dataswamp.org> <87pmcpo1wz.fsf@web.de> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="uYd2biEm6YEPInDD" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7895"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 12 06:17:24 2022 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 1p4bBr-0001mS-CH for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 12 Dec 2022 06:17:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4bB9-0002GU-7F; Mon, 12 Dec 2022 00:16:39 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p4bB6-0002GD-MZ for help-gnu-emacs@gnu.org; Mon, 12 Dec 2022 00:16:36 -0500 Original-Received: from mail.tuxteam.de ([5.199.139.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p4bB4-0003Oy-LK for help-gnu-emacs@gnu.org; Mon, 12 Dec 2022 00:16:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject :Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=meuet6xwouegLwgLitIXuYdJsVW5qhmznEMvQMA8370=; b=M1Gzkl3T55LfFR45vmLiq9BemL jeTFyun2et77IkbU0Yps8zEpqtA83+5m4I/fGA04U4S63u84U9n0bcv+7rgdT/6PEvC0/2gTshgti GVaZBdTY8Yp2Im3DEgeAleqO5ZxyxivSBoPbarUXZ8sjYeKT4AjhyCvYH4VTbuMrT9t1Q5JCzaBnb 04/2Px59RGQuXC9tWW+8QSlAtLn/w0wGdnsDqwc9fOviHpeIULcCX9k0G2gTq6yvk8IF0pLPQ0k9G pI9capL2Ox5qgMwVRHn7J7HSiPuEwbrralJaCNNeeAuQ1F6VoTSD77Dp+BQuJqdRwPtX+O2I2m1so Ec9WzVhg==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1p4bB0-0003PJ-KS; Mon, 12 Dec 2022 06:16:30 +0100 Content-Disposition: inline In-Reply-To: <87pmcpo1wz.fsf@web.de> 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.29 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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:141662 Archived-At: --uYd2biEm6YEPInDD Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 12, 2022 at 02:18:04AM +0100, Michael Heerdegen wrote: > writes: >=20 > > > > (let ((i 0) > > > > funs) > > > > (while (< i 100) > > > > (push `(lambda () ,i) funs) > > > > (cl-incf i)) > > > > (mapcar #'funcall funs)) > > > > > > Yes, but here there is no "new binding" exactly, rather the > > > value is hard-coded onto the lambda ... > > > > Look closely. There is one. Just at macro expansion (aka compile) > > time. >=20 > ?!? >=20 > The expansion of (push `(lambda () ,i) funs) is ^^^ To me, that one (well, if you squint, the others too) counts as a compile time binding, of sorts. Or well, pre-compile or something. It was the "poor human's closure" in pre-lexical times, after all. > #+begin_src emacs-lisp > (setq funs > (cons > (list 'lambda nil i) > funs)) > #+end_src Yes, the binding of i is effective before the lambda expression is "compiled" (whatever that means when you are playing interpreter, but it still means something, no?) > Stefan would say that this accumulates a list of function expressions in > FUNS, not a list of functions, strictly speaking. Works only because > the Lisp interpreter is made to be nice to everyone. FWIW, I find those languages (the ones trying to be nice) the most interesting. But they can be confusing, too :-) Cheers --=20 t --uYd2biEm6YEPInDD Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCY5a5JgAKCRAFyCz1etHa Rqg/AJ92IT85XF4JGDEqoc9k2xekjvAQ5QCdE0o2fz8S4lDlhyRL8hqNCv43m28= =htIx -----END PGP SIGNATURE----- --uYd2biEm6YEPInDD--