help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another question about lambdas


From: Emanuel Berg
Subject: Re: Another question about lambdas
Date: Sat, 25 Feb 2023 08:31:22 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Michael Heerdegen wrote:

>> 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?

With top-level let-closures "enclosed" defuns can use the
variables defined in the VARLIST of `let' as if they were
global variables, but they are not.

So perceived and real disadvantages of global variables won't
pester your Elisp.

And the advantages are, compared to local variables - also
using `let' - they keep their values between function calls,
and they can be shared/accessed by several functions.

Here is an example showing these two advantages/use cases:
  https://dataswamp.org/~incal/emacs-init/w3m/w3m-survivor.el

If there are other use cases I'm unaware of them.

And if you think about those two use cases, they do nothing
that global variables don't.

So, it's all about avoiding the downsides of global variables?

If so, it's enough - I'll take it. It makes the code more
pretty/cool and you don't use global variables.

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]