Created
August 19, 2012 19:51
-
-
Save kristianlm/3397261 to your computer and use it in GitHub Desktop.
how to do nested loops in C -> Elegant Scheme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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)) |
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
Are there any srfi's which will let me do something like: