No-argument (and) returns t

2019-06-18 04:32发布

问题:

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.

回答1:

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


回答2:

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.



回答3:

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.