[Top][All Lists]

[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 <> 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)


(let ((global-lexical 12))

(defvar global-dynamic 24)

(defun dynamic-test ()
  (message "%s" global-dynamic))


(setq global-dynamic 17)


(let ((global-dynamic 12))
--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™?


Marcin Borkowski

reply via email to

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