Chezscheme says "Exception: attempt to apply non-procedure #<void>" when I tried to print a pascal triangle

37 Views Asked by At

I'm new to scheme and I'm learning sicp.

I'm working on exercise 1.12 and tried to print a pascal triangle with the code below.

Cause I don't know much about scheme IO, I only used display procedure.

(define (pascal n k)
  (if (or (= k 1) (= k n))
    1
    (+ (pascal (- n 1) (- k 1))
       (pascal (- n 1) k))))

(define (prt_iter n row col)
  (if (< row n)
    ((display (pascal (+ row 1) (+ col 1)))
    (if (< col row)
      ((display " ")
        (prt_iter n row (+ col 1)))
      ((display "\n")
        (prt_iter n (+ row 1) 0))))
    (display "\nfinished")))

(define (prt n)
  (prt_iter n 0 0))

(prt 5)

The intepreter said "Exception: attempt to apply non-procedure #<void>".

I tried to print it manually:

(display (pascal 1 1))
(display "\n")
(display (pascal 2 1))
(display " ")
(display (pascal 2 2))
(display "\n")
; etc

and it worked.

Still I couldn't figure out what's wrong with it, especially "#<void>" confuses me a lot.

0

There are 0 best solutions below