From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32687 invoked from network); 7 Sep 2021 19:02:53 -0000 Received: from mx1.math.uh.edu (129.7.128.32) by inbox.vuxu.org with ESMTPUTF8; 7 Sep 2021 19:02:53 -0000 Received: from lists1.math.uh.edu ([129.7.128.208]) by mx1.math.uh.edu with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mNgMs-00GsYy-2X for ml@inbox.vuxu.org; Tue, 07 Sep 2021 14:02:50 -0500 Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by lists1.math.uh.edu with smtp (Exim 4.94) (envelope-from ) id 1mNgMq-002Xek-OM for ml@inbox.vuxu.org; Tue, 07 Sep 2021 14:02:48 -0500 Received: from mx2.math.uh.edu ([129.7.128.33]) by lists1.math.uh.edu with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1mNgMp-002Xef-VX for ding@lists.math.uh.edu; Tue, 07 Sep 2021 14:02:47 -0500 Received: from quimby.gnus.org ([95.216.78.240]) by mx2.math.uh.edu with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1mNgMn-007HRy-NQ for ding@lists.math.uh.edu; Tue, 07 Sep 2021 14:02:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=k8EdrnHE4HGX78CKnyQdKEhPNPKxH0pgyH42T6vv/FU=; b=tKY2onT5eMHK49DhGoEDi+cZsH LTc+rMmgFxJCFK0nxH405SyDC24YIYy14PsvWkleX1R8uzBssn1n4ueaK8Z9OqrRUB2Mo1ZsTcA1i Yn9iwMwWseGQ68ZXFWt5CQAXkYR5hZo2L9ToEUQ+puTCzxcoBAbBLsYHrcS03f+cTKiw=; Received: from mail.ericabrahamsen.net ([52.70.2.18]) by quimby.gnus.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNgMh-0000i7-1S for ding@gnus.org; Tue, 07 Sep 2021 21:02:41 +0200 Received: from localhost (c-71-197-232-156.hsd1.wa.comcast.net [71.197.232.156]) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id 3C001FA04B for ; Tue, 7 Sep 2021 19:02:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericabrahamsen.net; s=mail; t=1631041357; bh=k8EdrnHE4HGX78CKnyQdKEhPNPKxH0pgyH42T6vv/FU=; h=From:To:Subject:References:Date:In-Reply-To:From; b=ByMHV6eT3hP4vNPJYxQh+CkDrqguVJyl7EJ0UZRzuDYwEqwToUTE332a/aVnMqLxz JPG2Rh42568kTq2KuE8g44iJCfnSpxSj6TSA1sEc98xMpbCzm1zfDuhr5uoCxgppB+ TGm9nKjqmo/z1dgtm17Gljk0OXJSl4UcG6oHRH0g= From: Eric Abrahamsen To: ding@gnus.org Subject: Re: for a given emacs session: insert a subject with an increasing counter References: <87v93maplq.fsf@mat.ucm.es> <87h7f629rj.fsf@ucl.ac.uk> <87o89e85vg.fsf@mat.ucm.es> <87k0k2aynw.fsf@tullinup.koldfront.dk> <8735qpd3jj.fsf@mat.ucm.es> <87tuj5j6f9.fsf@gmail.com> <87wnnw747v.fsf@mat.ucm.es> <87ilzcnwc3.fsf@zoho.eu> Date: Tue, 07 Sep 2021 12:02:35 -0700 In-Reply-To: <87ilzcnwc3.fsf@zoho.eu> (Emanuel Berg's message of "Tue, 07 Sep 2021 19:12:44 +0200") Message-ID: <87fsuggqes.fsf@ericabrahamsen.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain List-ID: Precedence: bulk Emanuel Berg writes: > Uwe Brauer wrote: > >>> Just for your information, if you don't want a global >>> variable, you can use let: >>> >>> (let ((counter 0)) >>> (defun my-insert-add-counter () >>> (cl-incf counter) >>> (insert (int-to-string counter)))) >> >> Right, but it feels a bit counterintuitive: to define >> a function in a let. > > Very counterintuitive to the point I never thought about it > and wouldn't no matter how much Lisp I ever get to do... That's called a "closure", because the function "closes over" the let-bound symbol. Once evaluated, _only_ the function body has access to that symbol: it can treat it like a globally-defined variable, but no one else can see it. When lexical-binding is non-nil, you're always making closures: (setq lexical-binding t) (lambda (arg) (message "%S" arg)) --> (closure (t) (arg) (message "%S" arg)) The (t) is where the closed-over symbols and their current values would be stored, if there were any. It's sort of like the function's own private let-form. Eric