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: Another question about lambdas Date: Fri, 03 Feb 2023 01:20:19 +0100 Message-ID: <87h6w3bnwc.fsf@web.de> References: <87tu23kw9x.fsf@web.de> <861qp67wgm.fsf@gnu.org> <87wn6yyflc.fsf@web.de> <871qp5o05o.fsf@web.de> <87k02xm99a.fsf@web.de> <874jsoysal.fsf@dataswamp.org> <87tu0m8x13.fsf@web.de> <87357rnch0.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="39850"; 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 Fri Feb 03 01:21:08 2023 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 1pNjpE-000A9R-8E for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 03 Feb 2023 01:21:08 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNjog-0001JJ-L7; Thu, 02 Feb 2023 19:20:35 -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 1pNjod-0001De-Jo for help-gnu-emacs@gnu.org; Thu, 02 Feb 2023 19:20:33 -0500 Original-Received: from mout.web.de ([212.227.17.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNjoZ-0002Fw-W3 for help-gnu-emacs@gnu.org; Thu, 02 Feb 2023 19:20:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1675383620; bh=KOTdQMUMJzlGcZHbyE5A3Of8jJfxP3OskZe4WHRS7+M=; h=X-UI-Sender-Class:From:To:Subject:In-Reply-To:References:Date; b=ofOgH9RmOufiaqubrxuJq8nfui/RoeSbw9WfoQeItKcd0cpRcWoBTaMVuhk71EPIl 26wnEN+ejjIQiJTMpdC48WDk6ojPRvO/+OqenEnY28F4MFMcP3it8xOaNpJ2zfqx3t We2rXjFJNv8dxgluDiuRQRcACRjXHgFqJBYCuE/g1IpUUCKBceJY2svD2DOMu/Z0hJ k5M2T+ELNC/V/5w6+iRgiVb0UVbJtAR7OquN2enKGsDiYIpUeOlmp17zGO/xj/4jjn PKcH2R2MheWvWuglgJ402O9KmX1I34Uu1hZjPpekKN4kd4EiRBzjmkrr2C+jCyGOsv dPkfjZi4dfbMw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from drachen.dragon ([84.59.210.57]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MK56y-1p3KaA2zIE-00LYpb; Fri, 03 Feb 2023 01:20:20 +0100 In-Reply-To: <87357rnch0.fsf@dataswamp.org> (Emanuel Berg's message of "Mon, 30 Jan 2023 18:44:59 +0100") X-Provags-ID: V03:K1:BrSQ/bMygjkooILzEnlX3ORr1SlZg73NOhzaGzvjYtxuqVTLJZy QzLK0hnL74EgEY1QawPw5+AXZdXZr4NQ5sb/cksPo5se4SNM5Z2SY8P5bEJjzfDPX0NPbuo FRQn12n0eyW3j+XHGv6uRETeJuakyc8Ujh3bSJ+1bm/VRMXL5jOOHoDOP8sM1lLskgJWcU+ YSEzJsUXCZFS9f5Ge0c+w== UI-OutboundReport: notjunk:1;M01:P0:2REO8m1QOFA=;ZDmCcBt+fbqz5dPnIXNkZWsNhHx WN+vrYlcCm7gxMdVr743WkPFC75JHNYUxVGEPFFBnNvqKX2ohNweaotsuM6c6IrErAdDsiVv1 wK/ENx8BFcQBfMoNv6OgLl8RFWsahkosVYI5spBN6G1uhh1d2R78WxVL2lJItcWFkInPJmTnO 6NCeyamo8kii3HMkv6ZhjyW93AA8EpvaK1PPfepwnGQZwBYq5o5HrQ2fBGolsjZfp446S01YS 7p3DcwBheXi5Ze9GhyJvHCHWyslxiyfXjB1wC8eKx3aaHW9iVEjGn46hyCw/1LVQKKE9WeQJK UhHm/ftgxvswl1owIsWENIKCbrh9qNg5kiZ7guSha66NXw5jVOh54obbVUVzWQJkwqJnjulXj yUdpx3VD2GagmwOtHnrtcQi9V8kCy93l16dCLkiBMTfefy2ljVGnw0T825Q5h0xOxIUfRT8vg itebW8Dup4iTAg1ET3i3jjgYcrMMra41WTVBgswDGo52EOxG+vr+J8eMfZFrsemRLiXu6S+Fj L1/2SPKBGexoBbASX/jAAIUYtNmEbU5RZzW0aWnLPPTTJj5GRVKMYWpqpM/KPCzBkHvYrMPzr BbYO05xLxvESMvXlEJ0JY5o2W/1FTmnoIMQu13TdzaSDHhQc2ZUr+3EmXz5LODazn9fHyfeBo n7c5WNPYU115pSM6YebFeb+TBrLrebRW8eSGFFgKgkSIhksT3opn54PZXuSFsAumPTggFDXtT exC5F13kNihZrEy5T2+L0ryWpLhKI1gR3RINtno3CTWrAASynHszVPb0A9KkSmzPLeg5/nBe Received-SPF: pass client-ip=212.227.17.11; envelope-from=michael_heerdegen@web.de; helo=mout.web.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_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:142582 Archived-At: Emanuel Berg writes: > Are we talking lexical/static `let' inside or outside > `defun's? > > Inside defuns they are very practical, local variables, > basically, outside defuns they are interesting, rather, I have > found 2 use cases so far, first, what in other languages are > refered to as static variables (whose value don't reset > between calls), second, the possibility to share such > variables between functions. > > This file demonstrate those use cases, other than that I don't > know what one is supposed to do with them, really, and so far > they don't do anything global variables don't. So they are > a method to not have those, basically? Dunno if this is a good summary, I would be careful. I find the question a bit artificial - how is the classification global vs local functions motivated? The top-level lexical environment is empty, so top-level defuns are not interesting as closures. So we are actually only speaking about the case of functions defined anywhere besides top-level that are given a global name. In a functional language functions with a globally accessible name that have an alterable state are probably not that sexy - we are instead trying to make those functions pure, or try to restrict side effects to obvious well-defined things like creating a window. Useful cases that come to my mind are more of kind where the state is never altered but lexical binding eases the definition of bunches of functions - in a very simple case e.g. #+begin_src emacs-lisp (defun my-make-adder (n) (lambda (m) (+ m n))) (defalias 'my-1+ (my-make-adder 1)) (defalias 'my-1- (my-make-adder -1)) #+end_src Such lexical variables are still different from special top-level variables (`defvar's): They are private (not accessible "from the outside"). You can have several of them having the same name. They don't clobber a name space. And no binding created in any context outside of the lexical context where the functions are defined can ever change the value of those variables. Michael.