简体   繁体   中英

recursive scheme program to iterative

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM