Received: from mx0.gmx.net (mx0.gmx.net [213.165.64.100]) by h1439878.stratoserver.net (8.14.2/8.14.2/Debian-2build1) with SMTP id p9CGXJ85007837 for ; Wed, 12 Oct 2011 18:33:20 +0200 Received: (qmail 4984 invoked by alias); 12 Oct 2011 16:33:13 -0000 Delivered-To: GMX delivery to rainer.schoepf@gmx.net Received: (qmail invoked by alias); 12 Oct 2011 16:33:13 -0000 Received: from relay2.uni-heidelberg.de (EHLO relay2.uni-heidelberg.de) [129.206.210.211] by mx0.gmx.net (mx054) with SMTP; 12 Oct 2011 18:33:13 +0200 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id p9CGULVH010120 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 12 Oct 2011 18:30:21 +0200 Received: from listserv.uni-heidelberg.de (localhost.localdomain [127.0.0.1]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id p9CDoUV7000485; Wed, 12 Oct 2011 18:30:20 +0200 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 1821474 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Wed, 12 Oct 2011 18:30:20 +0200 Received: from relay.uni-heidelberg.de (relay.uni-heidelberg.de [129.206.100.212]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id p9CGUK0u032726 for ; Wed, 12 Oct 2011 18:30:20 +0200 Received: from ueamailgate01.uea.ac.uk (ueamailgate01.uea.ac.uk [139.222.131.184]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id p9CGTt82022335 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 12 Oct 2011 18:29:59 +0200 Received: from ueams01.uea.ac.uk (ueams01.uea.ac.uk [139.222.131.78]) by ueamailgate01.uea.ac.uk (8.13.8/8.13.8) with ESMTP id p9CGTt1D016222; Wed, 12 Oct 2011 17:29:55 +0100 Received: from [139.222.114.31] by ueams01.uea.ac.uk with esmtp (Exim 4.69) (envelope-from ) id 1RE1e2-0008RO-47; Wed, 12 Oct 2011 17:27:02 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 References: <4E95A9C2.6020607@residenset.net> X-Enigmail-Version: 1.3.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN, outgoing) X-CanIt-Geo: ip=139.222.131.78; country=GB; region=I9; city=Norwich; latitude=52.6333; longitude=1.3000; http://maps.google.com/maps?q=52.6333,1.3000&z=6 X-CanItPRO-Stream: UEA:outgoing (inherits from UEA:default,base:default) X-Canit-Stats-ID: 05FHQtTxC - 5f41537bada2 - 20111012 X-Scanned-By: CanIt (www . roaringpenguin . com) on 139.222.131.184 Message-ID: <4E95C086.7060806@morningstar2.co.uk> Date: Wed, 12 Oct 2011 17:29:58 +0100 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Joseph Wright Subject: Re: Church booleans To: LATEX-L@listserv.uni-heidelberg.de In-Reply-To: <4E95A9C2.6020607@residenset.net> Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: X-GMX-Antispam: 0 (Sender is in whitelist: joseph.wright@MORNINGSTAR2.CO.UK); Detail=5D7Q89H36p4L00VTXC6D4q0N+AH0PUCnBi0P5cROEGjO+pG7NAH/K+tf9SrVFtpLrKONl 2T9EL4W4U4jgzLbnCcGpk1z/zwmKT/K1fv3lD0=V1; X-Resent-By: Forwarder X-Resent-For: rainer.schoepf@gmx.net X-Resent-To: rainer@rainer-schoepf.de Status: R X-Status: X-Keywords: X-UID: 6925 On 12/10/2011 15:52, Lars Hellström wrote: > Last week, I was reading up a bit on lambda calculus (a subject with > which I suspect there are list members far more familiar than I am). One > thing that caught my eye was the definitions of True and False, using > the so-called Church booleans > > True = \lambda xy . x > False = \lambda xy . y > > These may look strange, but turn out to be two objects that are very > familiar to us: \use_i:nn and \use_ii:nn respectively (or \@firstoftwo > and \@secondoftwo, for those who still think in 2e terms (like me)). > Indeed, putting my mind in LaTeX mode made the lambda calculus concepts > much easier to digest. > > But with such thinking comes also the converse association: might LaTeX > programming benefit from borrowing concepts from lambda calculus? In > particular: might the Church booleans be useful as general-purpose > booleans in LaTeX3?!? > > (A rather early thought then was that Frank's generation probably knows > all about lambda calculus and therefore must have thought about this > already. But I don't recall having seen it discussed anywhere.) > > One thing that is really nice about the Church booleans is how they > support the logical operations. One can define > > \cs_new:Npn \and:nnTF #1 #2 { #1 {#2} {\use_ii:nn} } > \cs_new:Npn \or:nnTF #1 #2 { #1 {\use_i:nn} {#2} } > \cs_new:Npn \not:nTF #1 { #1 {\use_ii:nn} {\use_i:nn} } > > and go > > \cs_set_eq:NN \foo_a_bool \use_i:nn > \cs_set_eq:NN \foo_b_bool \use_ii:nn > \or:nnTF { > \and:nnTF { \foo_a_bool } { \foo_b_bool } > } { > \not:nTF { \foo_b_bool } > } {True} {False} > > to get the correct result True. These \and:, \or:, and \not: can even > operate on general \...:TF constructions, and they work correctly > regardless of whether the \...:TF is expandable or needs to be executed! > (Like e.g. \regex_match:nnTF.) This is already much nicer than what one > can easily get from the primitive \if... \fi conditionals. Using this > for LaTeX3 booleans would also have the interesting property that > "predicates" and TF forms become the exact same thing! > > I can imagine that a downside of using this would be that it suggests a > coding style that could be considered "too exotic". It sometimes seems > that l3 tries to make things look very much like they would in a > traditional imperative programming language, even though what goes on > under the hood can be quite different. A concept like Church booleans > rather furthers functional idioms of programming, where a lot of the > "data" you pass around is also "functions" (or partially applied > functions), that can be applied with little or no syntactic framing in > the source code. > > Now I wonder: Would it be useful? (I think it would.) Would there still > be time to change? Does it seem worth it? One obvious question is how easy would it be to support predicate decision making in such as scheme: \bool_if:nTF { \l_my_first_bool && ( \l_my_second_bool && !\l_my_third_bool ) } which is one of the reasons for the approach currently taken. -- Joseph Wright