Reputation: 1
need help on making these two recursive programs in scheme iterative? I made the recursion, but am stuck at creating an iteration for both.
question 1 - recursion
(define mylength
(lambda (l)
(cond
((null? l) 0)
(else (+ 1 (mylength (cdr l)))))))
question 1 - iteration?
question 2 - recursion
(define mylistref
(lambda (l index)
(cond
((= index 0)(car l))
(else
(mylistref (cdr l) (- index 1))))))
question 2 - iteration?
Upvotes: 0
Views: 62
Reputation: 117
Scheme does not have any looping structures so your only option is to use recursion if you are traversing over some kind of data structure. You can read more about it here
Upvotes: 1