From: Marcin Borkowski <mbork@mbork.pl>
To: Emanuel Berg <moasenwood@zoho.eu>
Cc: help-gnu-emacs@gnu.org
Subject: Re: [External] : How to create a higher order function?
Date: Tue, 05 Oct 2021 09:25:52 +0200 [thread overview]
Message-ID: <875yuc7x1b.fsf@mbork.pl> (raw)
In-Reply-To: <87czosqa3q.fsf@zoho.eu>
On 2021-09-29, at 06:28, Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> Marcin Borkowski wrote:
>
>> Try this code. Make sure you set `lexical-binding' to t,
>> e.g., by saving it to a file and visiting it again
>> or something.
>>
>> ;;; -*- lexical-binding: t; -*-
>>
>> (setq global-lexical 24)
>>
>> (defun lexical-test ()
>> (message "%s" global-lexical))
>>
>> (setq global-lexical 17)
>>
>> (lexical-test)
>>
>> (let ((global-lexical 12))
>> (lexical-test))
>>
>> (defvar global-dynamic 24)
>>
>> (defun dynamic-test ()
>> (message "%s" global-dynamic))
>>
>> (dynamic-test)
>>
>> (setq global-dynamic 17)
>>
>> (dynamic-test)
>>
>> (let ((global-dynamic 12))
>> (dynamic-test))
>>
>> Can you spot the difference? Can you see why the dynamic one
>> is better suited for options, i.e., you can temporarily set
>> it with `let' and it Just Works?
>
> You mean options not from a human user, but an Elisp program
> perspective? I.e., different subsystems use other subsystems
> with their own set of options?
Not sure if I understand.
By an "option" I mean a variable I (the user) can set, either via `setq'
(or customize) or via `let' (in my code) so that Emacs behavior is
changed (temporarily in the case of `let').
> I guess that is/would be cool, in particular if it would work
> in parallel ...
>
> Other than that, what I can see, you have provided the same
> old example we have seen many times in slightly different
> versions. It shows that lexical binding is less confusing and
> less error-prone. It also shows the confusion that arises from
> `let' because it not only behaves differently under lexical
> binding and dynamic binding, it also behaves differently with
> lexically and dynamically bound individual variables ...
I wouldn't say "less confusing" - both lexical and dynamical binding
serve their purposes, which are different.
> Split up the `let' is what I think, into slet, `dlet' (which
> already exists), and llet, an alias to `let' (or the other way
> around, doesn't matter), which would be the same as our `let'
> under lexical binding. Then remove all ugly preprocessor-style
> ;;; -*- lexical-binding: t; -*- and everyone can just use
> whatever they like with the different lets having their (and
> only their) behavior in the docstrings, and that behavior
> wouldn't change no matter any outside fiddling around.
You mean you could use the same variable sometimes with `slet',
sometimes with `dlet'? I'm not sure if that is easy or difficult to
implement.
Best,
--
Marcin Borkowski
http://mbork.pl
next prev parent reply other threads:[~2021-10-05 7:25 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-21 4:10 How to create a higher order function? Marcin Borkowski
2021-09-21 4:50 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-21 5:06 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-21 11:27 ` Leo Butler
2021-09-21 11:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-21 20:31 ` mm-uu-extract was: " Leo Butler
2021-09-21 22:11 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-24 9:02 ` Marcin Borkowski
2021-09-24 9:00 ` Marcin Borkowski
2021-09-21 15:49 ` [External] : " Drew Adams
2021-09-24 9:04 ` Marcin Borkowski
2021-09-24 9:38 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-24 16:50 ` Drew Adams
2021-09-24 17:11 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-25 6:36 ` Marcin Borkowski
2021-09-25 23:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-27 10:10 ` Marcin Borkowski
2021-09-28 1:41 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-28 17:14 ` Marcin Borkowski
2021-09-29 4:28 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-05 7:25 ` Marcin Borkowski [this message]
2021-10-05 7:38 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-05 9:53 ` dlet/let/slet (was: Re: [External] : How to create a higher order function?) Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-22 19:03 ` How to create a higher order function? Stefan Monnier via Users list for the GNU Emacs text editor
2021-09-22 20:53 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-22 23:50 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-24 8:57 ` Marcin Borkowski
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875yuc7x1b.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=help-gnu-emacs@gnu.org \
--cc=moasenwood@zoho.eu \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).