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

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

Re: How to create a higher order function?


From: Emanuel Berg
Subject: Re: How to create a higher order function?
Date: Wed, 22 Sep 2021 22:53:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

> I think what you meant was
>
>     (defun negate (fun)
>       "Return a function returning the logical opposite of FUN."
>       `(lambda (&rest args)
>         (not (apply ',fun args))))

Awesome docstring for `backquote' BTW (the complete set of
examples), make it even better by removing some whitespace
prior to the equals sign chars so the semicolon chars (the
Elisp comment initiators) can be aligned as well.

But didn't you always say one shouldn't quote lambdas?

Is this the exception that confirms the rule?

> I don't think so. Currently closures constructed in
> lexical-binding mode are not super efficient (back in
> Emacs-24, the focus was on providing lexical-scoping with
> clean semantics and without breaking or slowing down dynamic
> scoping. Efficiency of lexical-binding was secondary, and we
> haven't really attacked that yet).

Hm ... maybe this can be visualized somehow or
expressed diagramically.

What about the supposedly and maybe rightly so "industrial
strength" Lisps, how did they do it? (Yuk. That term isn't
appealing/useful when it comes to programming IMO.)

>     (defun negate (fun)
>       "Return a function returning the logical opposite of FUN."
>       (lambda (arg1 arg2)
>         (not (funcall fun arg1 arg2))))
>
> where I'd expect the (C) version to be faster by a quite
> significant margin (like more than a factor 2).

See? That's what I meant when I said `funcall' should be used.

Keep it uptime ...

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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