Skip to content

Instantly share code, notes, and snippets.

@kristianlm
Created August 19, 2012 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristianlm/3397261 to your computer and use it in GitHub Desktop.
Save kristianlm/3397261 to your computer and use it in GitHub Desktop.
how to do nested loops in C -> Elegant Scheme
;; I can't seem to convert this neat little
;; C code into elegant Scheme:
;;
;; // I didn't test this:
;; int c[20][20]
;; for (int x = -10 ; x < 10 ; x++)
;; for (int y = -10 ; y < 10 ; y++)
;; c[x+10][y+10] = x + y;
;; This is the best I've got so far:
(map (lambda (y)
(map (lambda (x) (+ x y))
(iota 20 -10)))
(iota 20 -10))
@kristianlm
Copy link
Author

Are there any srfi's which will let me do something like:

(map-ranges ((-10 10)
             (-10 10))
            (lambda (x y) (+ x y)))

@kristianlm
Copy link
Author

Or this:

(matrix-map (lambda (x y) (+ x y)
      (matrix-iota 20 -10 1 20 -10 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment