From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: Closures in Emacs and their usage scenarios. Date: Thu, 30 Sep 2021 05:27:18 +0200 Message-ID: <87k0iyoi95.fsf@zoho.eu> References: <87ilyjlxnn.fsf@logand.com> <87y27fjal0.fsf@logand.com> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26778"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:rGMAqgoln/+sYzqg8a/7xeaQ9M8= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 30 05:28:00 2021 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 1mVmjo-0006oh-0p for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 30 Sep 2021 05:28:00 +0200 Original-Received: from localhost ([::1]:45054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVmjm-000560-J4 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 23:27:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVmjL-00055p-J3 for help-gnu-emacs@gnu.org; Wed, 29 Sep 2021 23:27:31 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:37246) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVmjJ-0004HX-QV for help-gnu-emacs@gnu.org; Wed, 29 Sep 2021 23:27:31 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mVmjG-0006Hj-NY for help-gnu-emacs@gnu.org; Thu, 30 Sep 2021 05:27:26 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.help:133405 Archived-At: Hongyi Zhao wrote: > I asked this question based on the following related > concepts that I am currently considering: iterator, > generator, recursor and closure (a decorator in Python is > essentially a closure). According to the theory discussed by > John McCarthy, it seems that the recursor or recursive > Functions have a more important position in these concepts. > > http://www-formal.stanford.edu/jmc/recursive/recursive.html Recursion is a darling of CS instructors because the code often looks so neat (more mathematical/semantic) and it opens up the doors to speak about such neat things as the base and recursive case (maybe because it resembles the inductive proofs of math, again) OTOH iteration (i.e., loops) are considered a building block of "imperative" programming, e.g. C, which in CS culture don't rank as high as so-called functional programming (Lisp/Erlang/Haskell etc), where, instead of side-effect plagued iteration you have such things as tail recursion, recursion over trees in both directions, and more ... However in practice iteration is almost always better as it don't place function after function on top of each other on the stack, also iteration doesn't involve function call overhead proportional to the scope of the problem solved, as does recursion. With Elisp in particular, which is considered slow in general and even more so with respect to funcall overhead (this is what I've heard from the Gnus people anyway, maybe to some extent it is an excuse not ever to refactor Gnus insanely long and complicated defuns, still I believe them) - so with Elisp in particular don't do recursion, do iteration. If you don't like the Elisp CL for loop (cl-loop for ... ) - why BTW? I love it, and it has features the C for don't have, for example multiple iterators - but if you don't like it (too imperative/too explicit side effects or whatever reason) there are other loops that looks as neat or neater than does recursion ... -- underground experts united https://dataswamp.org/~incal