I have an expression: (map some-proc some-list)
which evaluates to, say, '(#f #f #f).
I want to check whether all booleans in this list are true. However,
(and '(#f #f #f)) returns '(#f #f #f), while I heed #f.
Now, if I (apply and '(#f #f #f)), I get the error:
and: bad syntax in: and in the DrRacket environment. That is confusing because the Racket Reference gives the example of (apply + '(1 2 3)) which seems to be identical to my problem.
What am I doing wrong and how I get my #f out of '(#f #f #f)?
you can use andmap for this:
> (andmap (lambda (x) x) '(#f #f #f))
#f
The problem stems from the fact that and is not a procedure, but a macro, in order to avoid the evaluation of all of its arguments.
It would work in Lazy Racket, though, where and is a procedure.
Just another way of doing it:
(foldr (lambda(x y) (and x y)) #t '(#f #f #f))
or I will rewrite uselpa's solution (andmap):
(andmap identity '(#f #f #f))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With