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

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

Re: Lambdas for beginners broken - help, please


From: Eduardo Ochs
Subject: Re: Lambdas for beginners broken - help, please
Date: Wed, 24 Jul 2024 13:43:38 -0300

On Wed, 24 Jul 2024 at 10:12, Michael Heerdegen via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Eduardo Ochs <eduardoochs@gmail.com> writes:
>
> > What do I need to read to learn how to adapt my code to the new
> > behavior of Emacs?
>
> I don't think you need to read anything, since you have already
> understood everything you need to know.
>
> I think I remember your libraries a bit.
>
> Unfortunately you will have to change your code so that it does not call
> lists as functions any more.
>
> And - unless you redefine `backquote' - something like
>
>   `(my-cool-new-lambda ...)
>
> with whatever tricky definition of `my-cool-new-lambda' will always
> return a list and thus be not `funcall'able.
>
> So if you need to construct lambda expressions using backquote - AFAIR
> that's what your code does - it's unavoidable to add some wrapper that
> `eval's the constructed lambda expression, like `eval', before you have
> a valid function value.

I don't use `(lambda ...) in eev, the problem is not that... the main
problem is that all my material for teaching Emacs to beginners says
that Emacs supports both a "traditional" Lisp, in which functions can
be lambda lists, and a "modern" Lisp, in which functions are compiled
things, and if you are a beginner who have never programmed before
then it's better to start by the "traditional" Lisp and by dynamic
binding, and only learn lexical binding after a few days...

...but I'll try to write more about that later. Let me ask a technical
question that will (probably) let me make everything in eev work with
recent Emacses.

In the version of Emacs from git that I have here -
19a18e487b8e2f0c1627b9cc98e601327e884eb2, from Tue Jul 23 21:00:23
2024 +0300 - I have this,

  (eval '(lambda (n) (+ n 2)) t)
    ;; -> #[(n) ((+ n 2)) (t)]

  (eval '(lambda (n) (+ n 2)) nil)
    ;; -> #[(n) ((+ n 2)) nil]

  (closurep (eval '(lambda (n) (+ n 2)) t))
    ;; t

  (closurep (eval '(lambda (n) (+ n 2)) nil))
    ;; t

even though the docstring for lambda still says that under dynamic
binding lambdas are self-quoting:

  lambda is a Lisp macro in ‘subr.el’.

  (lambda ARGS [DOCSTRING] [INTERACTIVE] BODY)

  Return an anonymous function.
  Under dynamic binding, a call of the form (lambda ARGS DOCSTRING
  INTERACTIVE BODY) is self-quoting; the result of evaluating the
  lambda expression is the expression itself.  Under lexical
  binding, the result is a closure.  Regardless, the result is a
  function, i.e., it may be stored as the function value of a
  symbol, passed to ‘funcall’ or ‘mapcar’, etc.

I guess that uncompiled closures will still be supported by some
years, and maybe the plan is to make lambdas in dynamic binding return
closures that are close enough to the original lambda list...

So, question: is there a recommended way to convert the result of

  (eval '(lambda (n) (+ n 2)) nil)

back to the

  (lambda (n) (+ n 2))

?

  Thanks in advance,
    Eduardo...



reply via email to

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