all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Andy Moreton <andrewjmoreton@gmail.com>, emacs-devel@gnu.org
Subject: Re: 7 logical-xor implementations in source tree
Date: Tue, 23 Jul 2019 18:41:09 +0200	[thread overview]
Message-ID: <D87F77D9-0D41-40B5-98A8-380EA926B38F@acm.org> (raw)
In-Reply-To: <jwv7e89rksb.fsf-monnier+emacs@gnu.org>

23 juli 2019 kl. 14.38 skrev Stefan Monnier <monnier@iro.umontreal.ca>:
> 
> I'm not convinced it's worth the trouble (we only have 7 uses so far
> and they all seem happy with a 2-arg xor).
> Especially since there are 2 different reasonable semantics.
> It can always be extended later if needed.

That's reasonable. Racket made it 2-arg (thanks for the reference, Basil); looks like they couldn't make up their minds either.

>> * Give it a compiler macro, for efficient partial application
> 
> Given how rarely it's used, I'm not sure it's worth the trouble.
> Luckily if we only accept the 2-args case this can be done very cheaply
> with defsubst or define-inline.

Yes, define-inline in particular will produce decent code.

I would probably use the negation, boolean equivalence, more often than xor myself.
Since `equiv' (placeholder name) is more readily thought of as an equivalence predicate, its n-ary semantics is subject to less debate.

Example implementations:

+(define-inline xor (arg1 arg2)
+  "Boolean exclusive-or: the non-nil argument if the other is nil, else nil."
+  (inline-letevals (arg1 arg2)
+    (inline-quote
+     (if ,arg1
+         (if ,arg2
+             nil
+           ,arg1)
+       ,arg2))))
+
+(defmacro equiv (&rest args)
+  "Boolean equivalence: t if arguments are all non-nil or all nil."
+  (cond ((null args) t)
+        ((null (cdr args)) `(progn ,(car args) t))
+        (t `(if ,(car args)
+                (and ,@(append (cdr args) '(t)))
+              (not (or ,@(cdr args)))))))




  reply	other threads:[~2019-07-23 16:41 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-22 18:48 7 logical-xor implementations in source tree Oleh Krehel
2019-07-22 21:47 ` Basil L. Contovounesios
2019-07-24 22:17   ` Basil L. Contovounesios
2019-07-24 23:15     ` Stefan Monnier
2019-07-24 23:44       ` Basil L. Contovounesios
2019-07-25 12:07         ` Mattias Engdegård
2019-07-25 17:28           ` Paul Eggert
2019-07-25 17:46             ` Mattias Engdegård
2019-07-28  7:09           ` Philippe Schnoebelen
2019-07-28  8:04             ` Alan Mackenzie
2019-07-28 19:43               ` Marcin Borkowski
2019-07-30  9:36                 ` Alan Mackenzie
2019-07-30 10:57                   ` Philippe Schnoebelen
2019-07-30 11:28                     ` Andy Moreton
2019-07-30 12:34                       ` Stefan Monnier
2019-07-30 14:25                         ` Barry Fishman
2019-07-31  3:16                           ` Richard Stallman
2019-07-31 15:20                             ` Barry Fishman
2019-07-31 15:42                               ` Stefan Monnier
2019-07-31 20:22                                 ` Basil L. Contovounesios
2019-07-31 21:15                                   ` Michael Heerdegen
2019-07-31 22:28                                   ` Mattias Engdegård
2019-07-31 23:39                                     ` Basil L. Contovounesios
2019-08-02 10:29                                       ` Mattias Engdegård
2019-08-02 10:59                                         ` Basil L. Contovounesios
2019-08-06 11:58                                           ` Mattias Engdegård
2019-07-31 20:31                               ` Michael Heerdegen
2019-07-31 21:38                                 ` Drew Adams
2019-07-31 22:03                                   ` Drew Adams
2019-07-31 22:05                                   ` Basil L. Contovounesios
2019-07-31 23:20                                     ` Drew Adams
2019-08-01  0:09                                       ` Basil L. Contovounesios
2019-07-31 17:12                   ` Marcin Borkowski
2019-07-23  8:39 ` Andy Moreton
2019-07-23  9:08   ` Basil L. Contovounesios
2019-07-23  9:14   ` Mattias Engdegård
2019-07-23 10:26     ` Andy Moreton
2019-07-23 10:40       ` Andreas Schwab
2019-07-23 12:11         ` Andy Moreton
2019-07-23 13:20           ` Basil L. Contovounesios
2019-07-23 13:54             ` Andy Moreton
2019-07-24 22:21               ` Basil L. Contovounesios
2019-07-23 10:44     ` Basil L. Contovounesios
2019-07-23 11:01       ` Yuri Khan
2019-07-25 21:46       ` Juri Linkov
2019-07-23 11:24     ` Noam Postavsky
2019-07-23 12:38     ` Stefan Monnier
2019-07-23 16:41       ` Mattias Engdegård [this message]
2019-07-23 17:12         ` Eli Zaretskii
2019-07-23 17:48         ` Paul Eggert
2019-07-23 19:45           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D87F77D9-0D41-40B5-98A8-380EA926B38F@acm.org \
    --to=mattiase@acm.org \
    --cc=andrewjmoreton@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.