[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to create a higher order function?
From: |
Marcin Borkowski |
Subject: |
Re: How to create a higher order function? |
Date: |
Fri, 24 Sep 2021 11:00:37 +0200 |
User-agent: |
mu4e 1.1.0; emacs 28.0.50 |
On 2021-09-21, at 13:27, Leo Butler <leo.butler@umanitoba.ca> wrote:
> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> Hi all,
>>
>> assume that I want a function which "inverts" the meaning of a given
>> predicate. Something that would turn `<' into `>=' etc.
>>
>> So, here's a better (at least: working) version (B):
>>
>> ;;; -*- lexical-binding: nil; -*-
>> (defun negate (fun)
>> "Return a function returning the logical opposite of FUN."
>> `(lambda (&rest args)
>> (not (apply ,(symbol-function fun) args))))
>
> I think negate would need to be a defmacro in this case, not a defun.
Maybe. I'm not really convinced.
> This construction, as it is, would return a list, not a lambda function.
>
> `(foo ,X bar) is equivalent to (list 'foo X 'bar).
>
>>
>>
>> It seems to work fine, even if it's a bit complicated.
>>
>> Of course, the more obvious way to do it is to use the first definition
>> under lexical scope (C):
>>
>> ;;; -*- lexical-binding: t; -*-
>> (defun negate (fun)
>> "Try to return a function returning the logical opposite of FUN."
>> (lambda (&rest args)
>> (not (apply fun args))))
>
> Obviously C is better.
>
> Q: I see you use mu4e. How do you get the code highlighted? (in my Gnus,
> the background is distinctive blue).
??? I don't do anything in particular apart from using a pretty old
version of mu/mu4e. And code is not highlighted in my emails.
Best,
--
Marcin Borkowski
http://mbork.pl
- How to create a higher order function?, Marcin Borkowski, 2021/09/21
- RE: [External] : How to create a higher order function?, Drew Adams, 2021/09/21
- Re: [External] : How to create a higher order function?, Marcin Borkowski, 2021/09/24
- Re: [External] : How to create a higher order function?, Emanuel Berg, 2021/09/24
- RE: [External] : How to create a higher order function?, Drew Adams, 2021/09/24
- Re: [External] : How to create a higher order function?, Emanuel Berg, 2021/09/24
- Re: [External] : How to create a higher order function?, Marcin Borkowski, 2021/09/25
- Re: [External] : How to create a higher order function?, Emanuel Berg, 2021/09/25
- Re: [External] : How to create a higher order function?, Marcin Borkowski, 2021/09/27
- Re: [External] : How to create a higher order function?, Emanuel Berg, 2021/09/27
- Re: [External] : How to create a higher order function?, Marcin Borkowski, 2021/09/28