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

[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: Eduardo Ochs
Subject: Re: [External] : Re: How do I pass a variable defined in a wrapping let, to a lambda?
Date: Sun, 13 Mar 2022 09:19:35 -0300

On Sat, 12 Mar 2022 at 21:08, Stefan Monnier via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> > 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)}"))
>
> Try
>
>     (dlet ((hi "Here: ") (a 22) (b 33)) (ee-template00 "{hi}{a}+{b}={(+ a 
> b)}"))
>
> or
>
>     (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.


Ouch, Stefan, sorry -

when you sent me that code I misread something and I thought that it
was just an incomplete prototype... it was not, only its docs were
incomplete. I have just added it to eev with very small changes - now
people can choose between `ee-template0', that needs dynamic binding
but is easier to understand, and `ee-template0-lex', that works in
both dynamic binding and lexical binding but uses macros...

The code is here:

http://angg.twu.net/eev-current/eev-template0.el.html#ee-template0-lex

Cheers =S,
  E.



reply via email to

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