From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Closures - do you understand them well? Date: Sat, 10 Dec 2022 10:34:24 +0100 Message-ID: <87y1rf1txv.fsf@gnu.org> References: <87lenh7vrn.fsf@web.de> <87tu25d77o.fsf@gnu.org> <87h6y5pt8k.fsf@web.de> <87bkodpqnk.fsf@web.de> <87k030tlfh.fsf@web.de> <87ilikxgkd.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37288"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.4; emacs 30.0.50 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 10 10:37:28 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 1p3wIR-0009XJ-R1 for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 10 Dec 2022 10:37:27 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p3wHx-0000on-Rl; Sat, 10 Dec 2022 04:36:57 -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 1p3wHq-0000oW-Mv for help-gnu-emacs@gnu.org; Sat, 10 Dec 2022 04:36:50 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p3wHq-0005Cu-FM for help-gnu-emacs@gnu.org; Sat, 10 Dec 2022 04:36:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-reply-to:Date:Subject:To:From: References; bh=Bxq+ZFs6aShIGOZq3Pd+wYgT07p/MySEP8/sbA4VtG0=; b=HWaGGk1M9yHdxc bgylO+qdWy91d+pmLAHTvkTGLXkOjzYNajqiHVi1ADvC2bU2XmNuf1Lf9qr9ojGwGCykEE4CsAo5i rZo5rU2CLk0AEtBTuVAr5btG8uMDF8NRwd1mC+3so3ekhXl/F9Cc+22TrGsNVQombef7I0+vu8HKS LpZ8Xx2QDoYqmCYHESLg6d8QkVBekc3qNn0wKNW6gsKSi/TJD5luLYnxWS2FhF1Pz2QsRr3zwcRAu QO1tmcDUE3kN1oU+PzCqCO9fZrhgew6cyv1/rKKJtFTQ+33pgVgN2DuKEvkZgCdxJ+nC4KC4O7YvJ OxJG53ksiwiOuI54Jx0Q==; Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p3wHo-000253-6o for help-gnu-emacs@gnu.org; Sat, 10 Dec 2022 04:36:49 -0500 Original-Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 838EE27C0054 for ; Sat, 10 Dec 2022 04:36:47 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sat, 10 Dec 2022 04:36:47 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeggddthecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfhgfhffvufffjgfkgggtsehttdertd dtredtnecuhfhrohhmpefvrghsshhilhhoucfjohhrnhcuoehtshguhhesghhnuhdrohhr gheqnecuggftrfgrthhtvghrnhepveevieekteekveeigfefffeivdetgeduvdffueeuud evgedttdehvdfhueevfffhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomhepthhhohhrnhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthi dqkeeijeefkeejkeegqdeifeehvdelkedqthhsughhpeepghhnuhdrohhrghesfhgrshht mhgrihhlrdhfmh X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 10 Dec 2022 04:36:46 -0500 (EST) In-reply-to: <87ilikxgkd.fsf@web.de> 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:141554 Archived-At: Michael Heerdegen writes: >> Write an expression that returns a list of 100 functions accepting >> zero arguments. `funcall'ing the Nth function must return N. Use a >> `while' loop or whatever you like but please not `dolist' or any >> tool that already handles this "problem" specifically. > > Would this be a valid solution? > > #+begin_src emacs-lisp > (let ((i 0) (funs)) > (while (<= (cl-incf i) 100) > (push (apply-partially #'identity i) funs)) > (nreverse funs)) > #+end_src Apparently it works although I don't see why. Where's the difference to this inlined version which returns (101 ... 101)? --8<---------------cut here---------------start------------->8--- (let ((i 0) (funs)) (while (<= (cl-incf i) 100) (push (lambda (&rest args2) (apply #'identity (append (list i) args2))) funs)) (mapcar #'funcall (nreverse funs))) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo