From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: 7 logical-xor implementations in source tree Date: Tue, 23 Jul 2019 18:41:09 +0200 Message-ID: References: <87tvbd9a8p.fsf@oremacs.com> <86wog9gn5n.fsf@gmail.com> <7AAB8009-DD68-4EA7-93CC-3B4A89FC8AFD@acm.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="101149"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Andy Moreton , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 23 18:41:24 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hpxqt-000QDD-SN for ged-emacs-devel@m.gmane.org; Tue, 23 Jul 2019 18:41:24 +0200 Original-Received: from localhost ([::1]:45676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpxqs-0003IO-Rd for ged-emacs-devel@m.gmane.org; Tue, 23 Jul 2019 12:41:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37186) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpxqq-0003IB-1E for emacs-devel@gnu.org; Tue, 23 Jul 2019 12:41:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpxqp-0007WQ-0a for emacs-devel@gnu.org; Tue, 23 Jul 2019 12:41:19 -0400 Original-Received: from mail202c50.megamailservers.eu ([91.136.10.212]:45300 helo=mail193c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hpxql-0007TP-Gz for emacs-devel@gnu.org; Tue, 23 Jul 2019 12:41:17 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1563900072; bh=Rc4tSzP3wVJ7t8aVuSBYrqpX6TfwVxWJlgYmHc/S/Ec=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=QJn7HHnXVx+os6NlzvjHQcmHnkvW7bTR5j9uS3SgMpkQib9ATktpvvHQmRMW2E41+ z3rXti3EVlnrnPas3ZZzqoUsNUml4AaGYZy3uBBmEcZ+Ogi8KQsqsQbGAbLZAX4uAd yxboa+FSRIQ5a0YAGNeScw+Ehlm6ZBYdwptelWXs= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] ([188.150.171.71]) (authenticated bits=0) by mail193c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x6NGf9X3001203; Tue, 23 Jul 2019 16:41:11 +0000 In-Reply-To: X-Mailer: Apple Mail (2.3445.104.11) X-CTCH-RefID: str=0001.0A0B0201.5D3738A8.0005, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=KsZjJ1eN c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=iRZporoAAAAA:8 a=1NsVrpoCiOjPsnn3F_4A:9 a=CjuIK1q_8ugA:10 a=NOBgFS-JBQ2l-kSd6-zu:22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 91.136.10.212 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:238849 Archived-At: 23 juli 2019 kl. 14.38 skrev Stefan Monnier : >=20 > 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 >=20 > 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)))))))