Your function is:
(define (tstFunc lst1 lst2) ; 0
(define (tstFunc-helper ; helper function 1
ls1 ; its 1st argument <-----------------\ 2
ls2 ; 2nd argument <--------------\ | 3
result ) ; 3rd argument | | 4
; | | 5
(if (or (null? ls1) (null? ls2)) ; | | 6
result ; return result, OR | | 7
(tstFunc-help ; call self with | | 8
(cdr ls1) ; as the next 'ls1' ----|--/ 9
(cdr lst2) ; as the next 'ls2' ----/ 10
(cons ; as the next 'result' 11
(tstFunc lst1 lst2) ; prefix this value (*) 12
result) ; to current "result", to 13
; construct the next "result" 14
))) ; 15
; 16
)
You define a helper function (1), but don't call it (16). A typical initial call will use some initial "result" value, like '()
for list construction.
You refer to arguments to the outer function, in your inner function (10,12). It is allowed, just highly probably not what you intended - in particular, lst2
"as the next 'ls2'" won't ever change, will always be the same list.
You're combining your lists (12) at each step by calling the main function (0), creating infinite recursion. You should use some 3rd function to combine them. Usually we combine the car
s of our lists, but sometimes the lists themselves are needed too, that's not the problem. But again you're using the wrong argument names there.
Since you build the result by consing (11), you probably want to return the final result (7) reversed back into the original order.