[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [External] : How to create a higher order function?
From: |
Marcin Borkowski |
Subject: |
Re: [External] : How to create a higher order function? |
Date: |
Tue, 28 Sep 2021 19:14:44 +0200 |
User-agent: |
mu4e 1.1.0; emacs 28.0.50 |
On 2021-09-28, at 03:41, Emanuel Berg via Users list for the GNU Emacs text
editor <help-gnu-emacs@gnu.org> wrote:
> Marcin Borkowski wrote:
>
>>> If they were local, how would people set them? Also if they
>>> were local, how would developers add e.g. another function
>>> that used them?
>>
>> Again: of course they couldn't be local. But if they were
>> global static, the whole "option setting" wouldn't work.
>
> Why not? Many programming languages with no notion of
> dynamic/special vs static/lexical scope has global variables
> with no problem using them to implement user options ...
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.
--8<---------------cut here---------------start------------->8---
;;; -*- 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))
--8<---------------cut here---------------end--------------->8---
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™?
Best,
--
Marcin Borkowski
http://mbork.pl
- Re: How to create a higher order function?, (continued)
- RE: [External] : How to create a higher order function?, Drew Adams, 2021/09/21
- Re: [External] : How to create a higher order function?, Marcin Borkowski, 2021/09/24
- Re: [External] : How to create a higher order function?, Emanuel Berg, 2021/09/24
- RE: [External] : How to create a higher order function?, Drew Adams, 2021/09/24
- Re: [External] : How to create a higher order function?, Emanuel Berg, 2021/09/24
- Re: [External] : How to create a higher order function?, Marcin Borkowski, 2021/09/25
- Re: [External] : How to create a higher order function?, Emanuel Berg, 2021/09/25
- Re: [External] : How to create a higher order function?, Marcin Borkowski, 2021/09/27
- Re: [External] : How to create a higher order function?, Emanuel Berg, 2021/09/27
- Re: [External] : How to create a higher order function?,
Marcin Borkowski <=
- Re: [External] : How to create a higher order function?, Emanuel Berg, 2021/09/29
Re: How to create a higher order function?, Stefan Monnier, 2021/09/22