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

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

Re: [External] : How to create a higher order function?


From: Emanuel Berg
Subject: Re: [External] : How to create a higher order function?
Date: Wed, 29 Sep 2021 06:28:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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?

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

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.

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




reply via email to

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