Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

kristianlm commented Aug 19, 2012

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

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

This comment has been minimized.

Copy link
Owner Author

kristianlm commented Aug 19, 2012

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
You can’t perform that action at this time.