1

My code is like this

(define (accumulate op initial sequence)
  (if (null? sequence)
      initial
      (op (car sequence)
          (accumulate op initial (cdr sequence)))))

(define seq '(#t #t #t #t))

(accumulate and #t seq))

I use ikarus, the error message is

Unhandled exception
 Condition components:
   1. &who: and
   2. &message: "invalid syntax"
   3. &syntax:
       form: and
       subform: #f
   4. &trace: #<syntax and>

Question is:

and can not be used as op in accumulate function?

If I modify the code above like this, then it works.

(accumulate (lambda (x y) (and x y)) #t seq)
kuan291
  • 47
  • 6
  • 2
    Possible duplicate of [Why (apply and '(1 2 3)) doesn't work while (and 1 2 3) works in R5RS?](http://stackoverflow.com/questions/17232240/why-apply-and-1-2-3-doesnt-work-while-and-1-2-3-works-in-r5rs). – C. K. Young Dec 20 '13 at 10:52
  • @ChrisJester-Young, thanks. Should I delete the post? I don't know how to do. – kuan291 Dec 20 '13 at 11:00
  • 1
    @kuan291 You don't need to delete it. Having duplicates on the site makes it more likely that other people have a chance of finding the answers they need (since if they search and find any of the duplicates, they'll get a pointer to the question that has an answer). This is well written question, and it clearly shows your code and the error message. This may well help people find answers to similar questions in the future. – Joshua Taylor Dec 20 '13 at 16:05

1 Answers1

1

and is not a procedure, it's syntax or a macro. It needs to be syntax because it doesn't evaluate all its arguments, it evaluates arguments left to right until it encounters #f.

Barmar
  • 741,623
  • 53
  • 500
  • 612