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: Fri, 09 Dec 2022 21:55:49 +0100 Message-ID: <87ilike1l8.fsf@gnu.org> References: <87lenh7vrn.fsf@web.de> <87tu25d77o.fsf@gnu.org> <87h6y5pt8k.fsf@web.de> <87bkodpqnk.fsf@web.de> <87k030tlfh.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="7116"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.4; emacs 30.0.50 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 Fri Dec 09 21:59:18 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 1p3kSk-0001fb-IN for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 09 Dec 2022 21:59:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p3kS7-00078j-Od; Fri, 09 Dec 2022 15:58: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 1p3kS5-00078E-W0 for help-gnu-emacs@gnu.org; Fri, 09 Dec 2022 15:58:38 -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 1p3kS5-0005zu-Hu; Fri, 09 Dec 2022 15:58:37 -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=gqSdR0FCvpmQ9aUcgCByVnOBcMhkWsO+mVfG8muozuU=; b=KECkqnJiCEaBRB WNZklW/pTYBV/kCexGcpGs54WS0KI+TljkgI7ERMIE2d6oNWGs+hiOLMsI7kj4FrKL7iADvK8ztuw ELUBd3nDVzszZg2iJBJIrtJNbakyf/CquMdRKbcj+hmRyOQRwgka4fAx5TCkhk1GaPa27JeCS32Rj S5mXNZh3CVx24uj1D+xYiUHMVZ6w6GMV/hR5B9b4chVB6A/wdvEeQLuZgPW812abs/cVL/b//Ef3k GdcLGYSrZvbbcSEGp0zo7q7DMN7PVSZCTm451CTmOPGT3msbSBgnf0R7khIQ4TEICYoE8lO3PBdT0 E7c7ctDAyip5odMadGIw==; 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 1p3kS1-0001Tk-79; Fri, 09 Dec 2022 15:58:36 -0500 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id 9AB0A27C0054; Fri, 9 Dec 2022 15:58:31 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 09 Dec 2022 15:58:31 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddvgddugeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvvefuffgjkfggtgesthdtredttdertdenucfhrhhomhepvfgrshhs ihhlohcujfhorhhnuceothhsughhsehgnhhurdhorhhgqeenucggtffrrghtthgvrhhnpe dujedtheduvdelffejkeetgedvheelhedvueefhfeukeekkeehvdfggeegffevgfenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhorhhnod hmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdekieejfeekjeekgedqieefhedv leekqdhtshguhheppehgnhhurdhorhhgsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Dec 2022 15:58:30 -0500 (EST) In-reply-to: <87k030tlfh.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:141531 Archived-At: Michael Heerdegen writes: > everyone): how to "fix" the code so that what some people expected is > the end result?...: > > 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. This time I'm prepared and have three versions making a new binding. Take this, Michael! :-) --8<---------------cut here---------------start------------->8--- (let ((i 0) (m (lambda (i) (lambda () i))) funs) (while (< i 100) (push (funcall m i) funs) (cl-incf i)) (mapcar #'funcall funs)) (let ((i 0) funs) (while (< i 100) (let ((j i)) (push (lambda () j) funs)) (cl-incf i)) (mapcar #'funcall funs)) (let ((i 0) funs) (while (< i 100) (push `(lambda () ,i) funs) (cl-incf i)) (mapcar #'funcall funs)) --8<---------------cut here---------------end--------------->8--- Oh, I forgot to `nreverse` funs so my Nth function returns 99-N instead. Good enough... Bye, Tassilo