Logo

Programming-Idioms

  • Go
  • Scheme
(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))

Iteration is tail-recursion.
import "fmt"
for i, x := range items {
    fmt.Printf("Item %d = %v \n", i, x)
}

The range clause gives you index i and value x at the same time as loop variables
with Ada.Text_IO;
use Ada.Text_IO;
for I in Items'Range loop
   X := Items (I);
   Put_Line (Integer'Image (I) & " " & Integer'Image (X));
end loop;

Assuming Items is an array of integers.

New implementation...