Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheme using and operator on reduce

Tags:

scheme

racket

I am trying to use logical operations on reduce, for example:

(reduce and '(#t #t #t) 0)

This gives me an error, I'm not sure why.

(reduce + '(1 2 3) 0)

This works perfectly fine, but when I try to use the built-in and operation, it fails. Can someone explain me why wouldn't this work? I am forced to use reduce on logical operation

like image 523
user3100209 Avatar asked Jun 21 '26 05:06

user3100209


1 Answers

reduce requires a function as its first argument, while and is a special form. Since special forms are not first class objects, they can not be used as arguments to functions (or be stored in variables).

An alternative to reduce in this case is

(every identity list-of-booleans)

while

(any identity list-of-booleans)

is a working alternative to (reduce or ...)

like image 154
Terje D. Avatar answered Jun 22 '26 19:06

Terje D.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!