From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: Defining functions within functions? Date: Tue, 24 May 2016 09:13:41 +0200 Organization: Aioe.org NNTP Server Message-ID: <864m9oj5cq.fsf@student.uu.se> References: <87k2ilbblk.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1464882098 24803 80.91.229.3 (2 Jun 2016 15:41:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 2 Jun 2016 15:41:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 02 17:41:26 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1b8UkJ-0002ml-6p for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jun 2016 17:41:19 +0200 Original-Received: from localhost ([::1]:48096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8UkF-0003uF-6o for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jun 2016 11:41:15 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!feeder1.xsusenet.com!nntpspool.opticnetworks.net!nntpspool01.opticnetworks.net!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 63 Original-NNTP-Posting-Host: EoOtCC1fCYcttx6jjhWUlA.user.gioia.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Mail-Copies-To: never X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:dLgpDZj7PEm70TPJa4/rP+0PjbI= Original-Xref: usenet.stanford.edu gnu.emacs.help:217845 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:110200 Archived-At: Michael Heerdegen writes: > Personally, I use `let' with lambdas most of > the time for local function definitions. > When things get too complicated (seems you > are at that point), instead of using lexical > closures as local functions, you can use > top-level defuns accepting additional > arguments, or higher-level functions (also as > top-level defuns) that take the essential > values as arguments and return a closure. Here is some terminology to wade thru - let's see if I get it right: "lexical closures as local functions" are the same as `let' and lambdas with the lexical scope enabled, which is the same as what is normally thought of as local functions, invisible and unavailable from anywhere else but from within the function where they are defined... "top-level defuns" are normal defuns as they is only one level in Elisp. (By the way, this is the reason for the elaborate, prefixed naming conventions, some-package-yada-yada-do-it, and the like.) What do you mean by "additional arguments" tho? What I can see (?) the only thing replaced (not added) is the let binding, by the function name! "higher-level functions" aren't at the level of the long-lost High Ones, but on the same level as the mere "top-level" Wolfrider defuns, because "higher-level" refers to those function accepting functions as arguments, as they are not on any other level scope-wise than the defuns. What do you mean "return a closure" tho? A closure is an association between a function and its scope - but higher-level functions can just as well return a normal value, e.g. (defun eat-list (operator &rest args) (apply operator args) ) (eat-list '+ 1 2 3 4) ; 10 (eat-list '* 1 2 3) ; 6 (eat-list '+) ; 0 <-- cool, btw (eat-list '*) ; 1 <-- Perhaps if you provide an example, it'll be easier grasp the "scope" of it :) -- underground experts united .... http://user.it.uu.se/~embe8573 Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic - so far: 40 Blogomatic articles -