3

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

1
  • 3
    and is not a function, as Terje D said, but you can make your own to pass around: (foldl (lambda (x y) (and x y)) #t '(#t #t)) returns #t :-) Commented Apr 20, 2014 at 20:42

1 Answer 1

4

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 ...)

Sign up to request clarification or add additional context in comments.

3 Comments

Are every and any standard Scheme functions/constructs?
@RSahu Almost. Like reduce they are specified in SRFI-1 List library
@Terje D. I am required to use reduce function. I think I can work my way around since I know and is special form and not a operator. Making my own and would be easier I think.. Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.