Referring to the code in part 1 use the substitution model


Q1) Consider the following code;
(define (add1-iter a-list)
(define (add1-helper curr-list result-list)
(if (null? curr-list)
result-list
(add1-helper (cdr curr-list)
(cons (add1 (car curr-list))
result-list))))
(add1-helper a-list '()))


Is this an example of head or tail recursion? Why?

Q2 )Referring to the code in Part 1, use the substitution model to illustrate what the result of calling (add1-iter '(1 2 3)) will be. Why is the list reversed ?

 

Solution Preview :

Prepared by a verified Expert
Programming Languages: Referring to the code in part 1 use the substitution model
Reference No:- TGS0654003

Now Priced at $30 (50% Discount)

Recommended (91%)

Rated (4.3/5)