Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No-argument (and) returns t

Both CL and Scheme define (and) to return t (or #t) with no arguments.

I'm trying to understand the rationale for this. My naive assumption is that an empty set is false, and passing in zero arguments feels like passing in nothing that can be true.

Edit: clojure follows the same convention. I must be missing some basic Lisp assumption.

like image 569
iter Avatar asked May 26 '15 19:05

iter


3 Answers

The empty product is 1. The reason is that 1 is a neutral element for *.

If you have the product of 2 and 3 and then multiply by the product of nothing, you will get 2*3*1 = 6. We can write

  (product (product 2 3) (product)) 
= (product 6 1) 
= 6

The same computation with and:

  (and (and #t #t) (and)) 
= (and #t ?) 
= #t

We want the empty (and) to give a value ? that doesn't affect the result. The answer is #t since #t is a neutral element.

(and x #t) = x   for all boolean x
like image 161
soegaard Avatar answered Nov 17 '22 12:11

soegaard


Here's a more intuitive answer: an "and" is like a checklist: you're "done" (that is, true) when all of the things on the list are true. Suppose someone gave you an empty checklist; in that case, you have nothing to check off, and you're trivially done.

like image 7
John Clements Avatar answered Nov 17 '22 11:11

John Clements


Here's my attempt to put it as simple as possible: An and expression is false if and only at least one of its arguments is false, otherwise it is true. So it is trivially true if there are no arguments.

like image 4
Rörd Avatar answered Nov 17 '22 12:11

Rörd