[Top][All Lists]

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

Re: [External] : Re: How do I pass a variable defined in a wrapping let,

From: Stefan Monnier
Subject: Re: [External] : Re: How do I pass a variable defined in a wrapping let, to a lambda?
Date: Sat, 12 Mar 2022 18:14:40 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> Here is something that I don't know how to port to lexical binding.
> My functions that call `ee-template00' are all defined in files with
> "-*- lexical-binding: nil; -*-" - they don't work if I put them in
> files with "-*- lexical-binding: t; -*-".

You can make it work by sprinkling enough `defvar`, of course: often
add `-*- lexical-binding: t; -*-` is all it takes, but sometimes you
have to work harder.

I remember battling with this code to beat it into submission by
restructuring it a bit so that it doesn't rely so heavily on
`eval` and dynamic scoping.  I must have sent you the resulting patch back
then (that was around the time we added it to GNU ELPA).

> ;; (let ((hi "Here: ") (a 22) (b 33)) (ee-template00 "{hi}{a}+{b}={(+ a b)}"))


    (dlet ((hi "Here: ") (a 22) (b 33)) (ee-template00 "{hi}{a}+{b}={(+ a b)}"))


    (defvar hi) (defvar a) (defvar b)
    (let ((hi "Here: ") (a 22) (b 33)) (ee-template00 "{hi}{a}+{b}={(+ a b)}"))

IIRC my patch changed `ee-template00` into a macro, instead, so the references
inside your string template had lexical access to the variables.


reply via email to

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