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

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

Re: Another question about lambdas


From: Michael Heerdegen
Subject: Re: Another question about lambdas
Date: Wed, 14 Dec 2022 03:22:40 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Arash Esbati <arash@gnu.org> writes:

> So here another one for you: What's the result of this expression under
> lexical binding?
>
> (let (_)
>   (defvar x)
>   (let* ((x 'l)
>          (f (lambda () x))
>          (x 'd))
>     (funcall f)))

For me?

Ok: the `defvar' marks the variable `x` special in the lexical scope
where it is called - which is the lexical scope introduced by the
outermost `let'.  So both bindings of `x` in the inner `let' get dynamic
scope, one is shadowing the other, and the result is `d` (the result is
also `d` when evaluated with lexical binding off).

That's described in (info "(elisp) Defining Variables") for anyone who
wants to read about backgrounds.  `dlet' is using this "trick" for its
own implementation.

A nice addition to the original version!

Michael.




reply via email to

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