From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: 7 logical-xor implementations in source tree Date: Fri, 26 Jul 2019 00:46:22 +0300 Organization: LINKOV.NET Message-ID: <87k1c523a5.fsf@mail.linkov.net> References: <87tvbd9a8p.fsf@oremacs.com> <86wog9gn5n.fsf@gmail.com> <7AAB8009-DD68-4EA7-93CC-3B4A89FC8AFD@acm.org> <8736ixni7q.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="176201"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: Mattias =?iso-8859-1?Q?Engdeg=E5rd?= , Andy Moreton , emacs-devel@gnu.org To: "Basil L. Contovounesios" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 25 23:54:40 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 1hqlh9-000jie-LC for ged-emacs-devel@m.gmane.org; Thu, 25 Jul 2019 23:54:39 +0200 Original-Received: from localhost ([::1]:35506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqlh8-0006Tz-NM for ged-emacs-devel@m.gmane.org; Thu, 25 Jul 2019 17:54:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38618) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqlh0-0006Tp-Hr for emacs-devel@gnu.org; Thu, 25 Jul 2019 17:54:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqlgz-0002sW-Gm for emacs-devel@gnu.org; Thu, 25 Jul 2019 17:54:30 -0400 Original-Received: from bumble.birch.relay.mailchannels.net ([23.83.209.25]:17547) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqlgz-0002q7-7u for emacs-devel@gnu.org; Thu, 25 Jul 2019 17:54:29 -0400 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id E29242C2350; Thu, 25 Jul 2019 21:54:27 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a10.g.dreamhost.com (100-96-83-224.trex.outbound.svc.cluster.local [100.96.83.224]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 6F4392C239F; Thu, 25 Jul 2019 21:54:27 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a10.g.dreamhost.com ([TEMPUNAVAIL]. [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.17.3); Thu, 25 Jul 2019 21:54:27 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Whispering-Cold: 5d6a14e302fefe56_1564091667763_1879423000 X-MC-Loop-Signature: 1564091667763:3382397235 X-MC-Ingress-Time: 1564091667763 Original-Received: from pdx1-sub0-mail-a10.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTP id E711C7EFB8; Thu, 25 Jul 2019 14:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=linkov.net; bh=Fg+na/ /10oCpkByqVPYsNEVbdK4=; b=o5fubPibpwMo1ud0V4aifUQpibb2Wcp/zGYkO8 24nq08Rm/knhySnA4XJ+4xTaohwo0dnXtMG2wV2xaoM0eeR3SpG2whW7xYXgYIel wFOThiuDxE2tEs91zFQjbnv3HWbosrKwzWqLUXA9PPqNHOPHT6YvRBDu7gvldYKU jky8A= Original-Received: from mail.jurta.org (m91-129-103-76.cust.tele2.ee [91.129.103.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTPSA id C211F82E56; Thu, 25 Jul 2019 14:54:16 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a10 In-Reply-To: <8736ixni7q.fsf@tcd.ie> (Basil L. Contovounesios's message of "Tue, 23 Jul 2019 11:44:25 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduvddrkeefgddtvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffuohhfffgjkfgfgggtgfesthekredttderjeenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdefrdejieenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepmhgrihhlrdhjuhhrthgrrdhorhhgpdhinhgvthepledurdduvdelrddutdefrdejiedprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopegtohhnthhovhhosgesthgtugdrihgvnecuvehluhhsthgvrhfuihiivgepud X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 23.83.209.25 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:238903 Archived-At: > 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. Shouldn't xor have an associative property: (xor a b c) =E2=89=A1 (xor a (xor b c)) =E2=89=A1 (xor (xor a b) c) > 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). Returning a non-nil argument as-is is a useful property. Most implementations lack this property, so better to use: (unless (and a b) (or a b)) But the implementation with 'cond' is nice too. Another useful property is to evaluate arguments only once that currently is not the case: (defvar a 0) (defvar b 0) (defmacro xor (a b) `(cond ((not ,a) ,b) ((not ,b) ,a))) (xor (setq a (1+ a)) nil) =E2=87=92 2 But I don't know if an implementation with such property is possible at all (without using temporary variables).