Gnus development mailing list
 help / color / mirror / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: ding@gnus.org
Subject: Re: for a given emacs session: insert a subject with an increasing counter
Date: Tue, 07 Sep 2021 13:44:15 -0700	[thread overview]
Message-ID: <87bl54glpc.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <87fsuguozt.fsf@zoho.eu> (Emanuel Berg's message of "Tue, 07 Sep 2021 22:09:26 +0200")

Emanuel Berg <moasenwood@zoho.eu> writes:

>>> 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.
>>
>> But ... isn't that what you get with lexical/static `let'
>> _in_ the function?
>
> Ah, now I understand what you mean. With `let' inside, the
> variable will reset, so it cannot count, but with `let'
> outside (the closure), as you say "it can treat it like
> a globally-defined variable".

That's right.

> "globally-defined", very good!
>
> Oh, no!
>
> I didn't know of this (never seen it). I have used global
> variables to hold the "state" (be a memory between function
> calls) but I've also done more involved solutions like
> properties and even self-modifying code :O
>
> And all the while, it was this easy ...

TBH, I've never actually used a closure in anger, probably just because
it doesn't occur to me. I'll bet if I went back and looked over the code
I've written in the past I could find some situations where I could have
used them, but... *shrug*


  parent reply	other threads:[~2021-09-07 20:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30 16:01 Uwe Brauer
2021-08-30 16:10 ` Eric S Fraga
2021-08-30 18:46   ` Eric Abrahamsen
2021-08-31  6:50   ` Uwe Brauer
2021-08-31  6:58     ` Adam Sjøgren
2021-08-31 15:42       ` Uwe Brauer
2021-08-31 15:54         ` Adam Sjøgren
2021-09-02  8:15           ` Uwe Brauer
2021-09-04 15:30           ` [misunderstanding] (was: for a given emacs session: insert a subject with an increasing counter) Uwe Brauer
2021-09-07 20:04             ` Emanuel Berg
2021-09-01  3:55         ` for a given emacs session: insert a subject with an increasing counter Bodertz
2021-09-04 15:25           ` Uwe Brauer
2021-09-07 17:12             ` Emanuel Berg
2021-09-07 19:02               ` Eric Abrahamsen
2021-09-07 19:25                 ` Emanuel Berg
2021-09-07 20:09                   ` Emanuel Berg
2021-09-07 20:35                     ` Emanuel Berg
2021-09-07 20:44                     ` Eric Abrahamsen [this message]
2021-09-21  3:32                       ` Emanuel Berg
2021-09-21 19:12                         ` Bodertz
2021-09-21 21:56                           ` Emanuel Berg
2021-08-31  7:44     ` Emanuel Berg
2021-08-31  7:56       ` Emanuel Berg
2021-08-31 16:01       ` Uwe Brauer
2021-08-31 16:29         ` Eric Abrahamsen
2021-08-31 19:06           ` Uwe Brauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bl54glpc.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=ding@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).