[plt-scheme] Outer-inner loops in Scheme?

From: Grant Rettke (grettke at acm.org)
Date: Mon May 14 09:06:57 EDT 2007

Hi folks,

Last night I looked at a solution to a programming problem and the
typical approach was to use an inner and outer loop (think C or Ruby).
My approach in Scheme was to do something like the following:

(define test
  (λ ()
    (outer-inner-loop 0 0 9 9)))

(define outer-inner-loop
  (λ (x y x-max y-max)
    (begin
      (printf "~a ~a~n" x y)
      (cond [(and (>= x x-max) (>= y y-max)) 'done]
            [(< y y-max) (outer-inner-loop x (add1 y) x-max y-max)]
            [else (outer-inner-loop (add1 x) 0 x-max y-max)]))))

(test)

Is this the typical way you would implement "outer-inner looping" in Scheme?

Posted on the users mailing list.