Search code examples
scheme

Using AND with the apply function in Scheme


Why doesn't the following work?

(apply and (list #t #t #f))

While the following works just fine.

(apply + (list 1 3 2))

This seems to be the case in both R5RS and R6RS?


Solution

  • and isn't a normal function because it will only evaluate as few arguments as it needs, to know whether the result is true or false. For example, if the first argument is false, then no matter what the other arguments are, the result has to be false so it won't evaluate the other arguments. If and were a normal function, all of its arguments would be evaluated first, so and was made a special keyword which is why it cannot be passed as a variable.