[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.
- Re: Another question about lambdas, (continued)
- Re: Another question about lambdas, Emanuel Berg, 2022/12/10
- Re: Another question about lambdas, Arash Esbati, 2022/12/10
- Re: Another question about lambdas, Michael Heerdegen, 2022/12/10
- Re: Another question about lambdas, Michael Heerdegen, 2022/12/10
- Re: Another question about lambdas, tomas, 2022/12/11
- Re: Another question about lambdas, Michael Heerdegen, 2022/12/11
- Re: Another question about lambdas, tomas, 2022/12/12
- Re: Another question about lambdas, Michael Heerdegen, 2022/12/12
- Re: Another question about lambdas, Arash Esbati, 2022/12/13
- Re: Another question about lambdas,
Michael Heerdegen <=
Re: Another question about lambdas, Gregory Heytings, 2022/12/10