Originally I posted one question "understanding a tail-recursive vector->list answer" and this is additional questions. my general understanding in scheme is really vague. so I have now several more questions:
;;;;;; original code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define vector->list:rec
(lambda (v)
(letrec ((helper
(lambda (vec r i)
(if (< i 0)
r
(helper vec (cons (vector-ref v i) r) (- i 1)) ;; Q1
))))
(if (> (vector-length v) 0) ;; line 9
(helper v ;; line 10
(cons (vector-ref v (- (vector-length v) 1)) '())
(- (vector-length v) 2))
'()))))
Q2) tail recursion which makes me really difficult to understand. I understood why they need tail recursion and basically they use it to avoid iteration, so they use helper as intermediate routine.. so they can avoid put each iteration into stack.... something like this. and letrec/lambda expression like here:
;;;;;;;;;letrec/lambda express;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (some-procedure...)
(letrec ((helper (lambda (x)
...
(if some-test?
(helper ...))))) ; recursive call --- Q2-1
...
(helper ...) ; call to recursive local procedure ---- Q2-2
...))
line Q2-2: why this is 'local recursive'? 'local' sounds to me that recursive for intermediate routine...here intermediate means that my understanding..
[my confusion] tail recursive is should not iterate(calls) itself until at the end of the entire program - so shouldn't be in the intermediate routine.. = shouldn't be inside helper? based on my understanding until now... helper is for intermediate routine which encapsulated in letrec expression..?.) so only calls itself in the end.(my meaning..: outside letrec..?).