Logo

Programming-Idioms

History of Idiom 7 > diff from v60 to v61

Edit summary for version 61 by Dodopod:
New Scheme implementation by user [Dodopod]

Version 60

2017-04-17, 18:51:49

Version 61

2017-06-07, 15:45:20

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
(define (display-list items)
  (define (display-list items i)
    (if (not (null? items))
        (begin
          (display (string-append
                    (number->string i)
                    ": "
                    (number->string (first items))
                    "\n"))
          (display-list (rest items) (+ i 1)))
        'done))
  (display-list items 0))
Comments bubble
Iteration is tail-recursion.