Here is the code I came out (to display all pairs of balanced parentheses with length n)
(define (combine-list l r)
(append l (cons r '())))
;(combine-list '(1 2 3) '(4 4))
(define(bps n)
(bps-iter '() (/ n 2) 0 0))
(define (bps-iter lst n open close) (;(display open) (display close) (display "\n")
(cond ((eq? n close) (display lst))
(else ((if (> open close)
(bps-iter (combine-list lst 1) n open (+ 1 close) ))
(if (< open n)
(bps-iter (combine-list lst 0) n (+ open 1) close)))
)
)))
(bps 4)
And it turned out as
application: not a procedure;
expected a procedure that can be applied to arguments
given: #<void>
arguments...: [none]
Is there any problem when it finished calling (eq? n close) and get back to 'else' to look for another set of parenthesis?