emacs-devel
[Top][All Lists]
Advanced

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

Re: 7 logical-xor implementations in source tree


From: Basil L. Contovounesios
Subject: Re: 7 logical-xor implementations in source tree
Date: Tue, 23 Jul 2019 11:44:25 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Mattias Engdegård <address@hidden> writes:

> Some naïve suggestions:
>
> * Call it `xor', to go with `and' and `or'

+1

> * Make it n-adic, taking at least 1 argument (since the operation has no 
> identity)

That depends on the preferred semantics, right?  What semantics are you
suggesting?  Judging from online discussions I've come across, there's
more than one way to skin this cat.

I'm not convinced an n-ary xor function would be that useful in Emacs,
but I'm not opposed to it at all.  I'm interested to see arguments for
and examples of it.

Most people seem to define n-ary xor as a parity check (i.e. its result
is non-nil if the number of non-nil arguments is odd).

How often does this specific need crop up in Emacs that can't already
be handled more generally by bool-vectors or custom code like
(cl-oddp (length (delq nil list)))?

OTOH, a definition like the following:

  (defsubst xor (cond1 cond2)
    (cond ((not cond1) cond2)
          ((not cond2) cond1)))

not only performs simple logical xor more efficiently, but also returns
whichever of the two arguments is non-nil (though I can't imagine when
this last detail would ever be useful).

> * Make it a function, so that it can be used with `apply' etc.

Definitely, using either defsubst or define-inline.

> * Give it a compiler macro, for efficient partial application

That's already done by define-inline, right?  Since I'm not familiar
with compiler macros, can you please explain how they afford efficient
partial application?

> There is probably already something like this in CL, like everything else.

I'm not a CL expert, but some quick online searching did not reveal
much.  I had previously taken inspiration from Racket's boolean
operators, though: https://docs.racket-lang.org/reference/booleans.html

Thanks,

-- 
Basil



reply via email to

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