Reputation: 99
I am getting the following error "and: bad syntax in: and
#lang racket
(define fold
(lambda (fn lst)
(if (null? (cdr lst))
(car lst)
(fn (car lst) (fold fn (cdr lst)))
)
)
)
(define none-diff?
(lambda (lst num)
(if (even? num)
(fold and (map even? lst))
(fold and (map odd? lst))
)
)
)
I try foldr in szScheme , the same error , I do not know why ?
"and" and "+" are function , but ?
Upvotes: 2
Views: 299
Reputation: 15793
(fold and
(map (even? (list 1 2 3))))
fold
almost sure requires 3 argumentsand
is not a function, but a special formmap
a single argumentUpvotes: 1
Reputation: 7568
And
isn't function, but macro. And macros can't be used as argument for higher-order functions (for example map
, apply
or foldl
variants).
In this case, you can use andmap
:
> (andmap even? (list 2 4 6))
#t
> (andmap even? (list 1 2 3))
#f
Upvotes: 4