From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: cl-loop - do you understand it well? Date: Wed, 21 Dec 2022 09:12:12 +0100 Message-ID: <877cylmazn.fsf@web.de> References: <87zgbwyp46.fsf@dataswamp.org> <87k02zkrzw.fsf@web.de> <87wn6zhyna.fsf@disroot.org> <877cyzyogm.fsf@web.de> <87r0x6iisg.fsf@disroot.org> <87bko9o0tm.fsf@web.de> <87tu1xr182.fsf@dataswamp.org> <87bko4m6ej.fsf@web.de> <871qoyoq0u.fsf@dataswamp.org> <874jtt36sh.fsf@web.de> <87h6xr872h.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33030"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 21 09:13:10 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 1p7uDt-0008PE-V4 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 21 Dec 2022 09:13:09 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7uDB-0000BX-92; Wed, 21 Dec 2022 03:12:25 -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 1p7uD6-0000BK-Mg for help-gnu-emacs@gnu.org; Wed, 21 Dec 2022 03:12:21 -0500 Original-Received: from mout.web.de ([212.227.15.4]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7uD4-0000b0-MI for help-gnu-emacs@gnu.org; Wed, 21 Dec 2022 03:12:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1671610333; bh=hHqBoEvdoAUlKvp02r61TGgS914OOWcDCMoBE1MtbQI=; h=X-UI-Sender-Class:From:To:Subject:In-Reply-To:References:Date; b=HiLFqZSWiKZ8SuP+uXOI+mvQN5/UpOso/HsFKTmPz3v9g6uDGEvtz9jwMA/ZdNi1N bTjZZZ3qHCadLtoIu9UJkBbI8xgE50gjtL+/VoOWVYEAZd6ha7F/1V+noFI0beSrkp /l31KpUrDdwh9TM5siL8vXeljYzKhWTXHP0etTF7kC/EnH/JBErG61RzM2o5iBjfZO /bJMrFjZuQ9rR4ykb2Gc0+ZHfjeT1VGH11nb94/Zqm0sZkrCip8Pzoc22NwxmCtCJf VH55EpII0JAzogOefLVOJUIQB1x8Vvero3LXVQ+1BRP0HwzEJop1IpQ7uK/iO4eugZ 9ulKuiGwxuNmg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from drachen.dragon ([92.76.236.199]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MIc7N-1p4p8y28o9-00EbZX; Wed, 21 Dec 2022 09:12:13 +0100 In-Reply-To: <87h6xr872h.fsf@dataswamp.org> (Emanuel Berg's message of "Mon, 19 Dec 2022 21:36:06 +0100") X-Provags-ID: V03:K1:zArM3o5AX88gBepV69P/kwCV4wF3aParlq1p8U3uvDWc4+cz1m2 qPd9JACfk22Ru5ry7AYTjn9U/SkunnoRxVovxNY1n+wjrU7VK1rRlUZNG9a5GatNJsAW4Cl 1Ue69CIpFv+pYgVNpJDplyusQeovJLQWV6xziwGhLNhEbVku7EEhoz2Yb05W/xCB8T2lncG 7G+0vA9rMa/17j/B+nHxw== UI-OutboundReport: notjunk:1;M01:P0:a5iEJDdeyzA=;ooWxCA6DEcvVp5O/aEDqKZn45fL +8s9oDgpFqxLIWw3BCy8Wc667haJb4/hQqv/1vHaA9rG7eYbe9IOkJXJcl5X/vytBObCzyC4Y pqu+3mJaqH1maIkzZH6qjl7MRcQL7YWNzD37b5VPET/rrwgnDAS5s70RvlTmyWppwpE0VNQFP 4ugy50VNONwdHd9jVXh+UoESKzKCSBHsV3K05xYux8rvMR4CeuxvsueSbh43zdRWl8fN6q5c9 1DyjMPFdkHPqSrmuz0Ee5zRajeGcqzlLIlSxKPNaIZUr9jq55BmvtxfFwKfyR5r9Ysxa3tYLn TVEqSTVPsfg8nsgwP807VDr7XvPC7GV3CpuHib3IesPC9zcyShttN6SSlm8JUV5Yj6RQ+5Fl2 YVpECx6GB1ub00Qbe+m7CiC/qoUXDyoJ+xRuKVuh0NArFVd4jn0oOJqslvTd1qNyzMZmKFSLA DUEMNvARkahD9EJXxJcv64HMyui+gUz50tzhIf/M1iqLTqQJlr85dfH9P/71BjNG9seBQsbW9 y7O/lyjH6vwIykOE3+AGAlqPV2qXFiuR7XGjflhaHKPucgv2an5WIBE+hQ1MKcS7ecCO8syuE BN9N5ResDcjK4ahi6hA/33p0kO72e9vIv2tgUNWMtR24gFrP+YIxWhEu0xztQsTL+QFCqOOhT R+TwhSB0fMEO1MdnPHw/kw+oxpW2b9RZIsHMCNqOmGHCY0eTNz3L8ymnbGM36iwfPiM0l/3sl BFDdw8xSXqZV81hHy0hA/WYNMNI7YotvGDd8EjGf02KZVY4H/KFj5nMVEkcSZnkgrV+wTBGO Received-SPF: pass client-ip=212.227.15.4; envelope-from=michael_heerdegen@web.de; helo=mout.web.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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:141891 Archived-At: Emanuel Berg writes: > > (cl-block nil > > (let* ((i 0) > > (funs nil)) > > (while (<= i 1) > > (setq funs (nconc funs (list (lambda nil i)))) > > (setq i (+ i 1))) > > (apply #'+ (mapcar #'funcall funs)))) > > > No, where does the 4 come from? There are two closures in FUNS, and both share the same lexical variable i. When the closures are `funcall'ed i is bound to 2, which is the value i had when the loop is exited. 2*2=4. The goal of this exercise was to demonstrate that closures share modifiable environments instead of copies of values present at closure creation time. Michael.