I was trying with the following code in racket and MIT scheme, surprise me that the compiler throw err
(foldr and #t '(#t #t #f))
Is there any way to use reduce/fold way to check if a list contains only true or false? I know a lambda can do the job, but it really make we wonder why this is not a valid code. I remember I can do it in Haskell.....
TIA.
and
is a macro, so it doesn't have a value by itself. Specifically, it short-circuits evaluation, and using it as you tried to will not make any sense. For that reason, Racket has andmap
which you can use in such cases. (Other implementations have similar functionality under different names -- for example, srfi-1 uses every
.)
And is a macro and can not be used as a function. Put it in a function:
(foldr (lambda (a b) (and a b)) #t '(#t #t #f))
This works in guile:
(primitive-eval (cons 'and '(#t #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