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

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

Re: Closures - do you understand them well?


From: Michael Heerdegen
Subject: Re: Closures - do you understand them well?
Date: Sat, 28 Jan 2023 01:44:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Emanuel Berg <incal@dataswamp.org> writes:

> Michael Heerdegen wrote:
>
> > The (unevaluated) expressions are just lists. As values they
> > are "quoted lambdas" with all of the problems they come
> > with. The Elisp interpreter still accepts them as
> > function values.
>
> Okay, why, for technical reasons?

Is your question why they are (still) accepted?  I'm not an expert, but
I'll try to give an answer.

In the dynamical binding dialect, lambda expressions were
self-evaluating expressions: the function value was identical (`equal')
to the evaluated expression (when interpreting uncompiled code).  See
the definition of `lambda' in subr.el.

That fact could be exploited to build function values with certain
properties in a copy-and-paste like style (using backquote expressions,
typically).  "Poor-mans closures" already had been mentioned.

Old code still uses such techniques so I guess it would break too
much of such stuff if such values would not be supported any more.

Oh, and of course, since the Emacs interpreter has to support both
dialects at the same time (you can use packages with lexical binding
enabled and disabled in one and the same session), the interpreter has
to support such values anyway since they are valid in one dialect.
AFAIU, conceptually the type of binding is a property of the code - the
interpreter just can run both types of code.


> And what values are the correct function values then?

Lexical closures use a different representation - see

  (info "(elisp) Closures")

The actual structure is not interesting for programming any more.  And
in compiled code or natively compiled code function values are not such
nicely explorable lists anyway.

Michael.




reply via email to

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