## Lambda Calculus Boolean

 FP  Lambda   Introduction   Examples    Bool    Ints    Lists   others

Boolean values can be defined in the Lambda Calculus, although they are often "built into" programming languages based on Lambda Calculus.

 ```let TRUE = lambda a. lambda b. a, FALSE = lambda a. lambda b. b in let AND = lambda p. lambda q. p q FALSE, OR = lambda p. lambda q. p TRUE q, NOT = lambda p. lambda a. lambda b. p b a, IF = lambda p. lambda a. lambda b. p a b, EQ = lambda x. lambda y. if x = y then TRUE else FALSE in {simple test:} IF TRUE 1 (-1) :: IF FALSE (-2) 2 :: IF (OR FALSE TRUE) 3 (-3) :: IF (AND FALSE TRUE) (-4) 4 :: IF (NOT FALSE) 5 (-5) :: IF (EQ 1 1) 6 (-6) :: IF (OR (EQ 1 2) (EQ 2 2)) 7 (-7) :: nil {\fB Define Boolean From Scratch. \fP} ```

The example defines `TRUE', `FALSE', `AND', `OR', etc. from first principles but defines `EQ' using the built in `=' which is of course a cheat (to keep the example small). However, the section on integers shows how to define `ISZERO' which could be used to define `EQ' from first principles.

 let TRUE = lambda a. lambda b. a, FALSE = lambda a. lambda b. b in let AND = lambda p. lambda q. p q FALSE, OR = lambda p. lambda q. p TRUE q, NOT = lambda p. lambda a. lambda b. p b a, IF = lambda p. lambda a. lambda b. p a b, EQ = lambda x. lambda y. if x = y then TRUE else FALSE in {simple test:} IF TRUE 1 (-1) :: IF FALSE (-2) 2 :: IF (OR FALSE TRUE) 3 (-3) :: IF (AND FALSE TRUE) (-4) 4 :: IF (NOT FALSE) 5 (-5) :: IF (EQ 1 1) 6 (-6) :: IF (OR (EQ 1 2) (EQ 2 2)) 7 (-7) :: nil {\fB Define Boolean From Scratch. \fP}

Also see [Ints] and [Lists].

window on the wide world:
 The Darwin Awards V: Next Evolution

 Linux  Ubuntu free op. sys. OpenOffice free office suite, ver 3.4+ The GIMP ~ free photoshop Firefox web browser FlashBlock like it says!

λ ...
 :: list cons nil the [ ] list null predicate hd head (1st) tl tail (rest)

 © L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated), Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University, was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.) Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Thursday, 11-Feb-2016 02:13:48 EST.