Skip to content

Instantly share code, notes, and snippets.

@muspellsson
Created June 9, 2012 11:05
Show Gist options
  • Save muspellsson/2900579 to your computer and use it in GitHub Desktop.
Save muspellsson/2900579 to your computer and use it in GitHub Desktop.
Identity matrix generation in Scheme
(define (identity n)
(letrec
((uvec
(lambda (m i acc)
(if (= i n)
acc
(uvec m (+ i 1)
(cons (if (= i m) 1 0) acc)))))
(idgen
(lambda (i acc)
(if (= i n)
acc
(idgen (+ i 1)
(cons (uvec i 0 '()) acc))))))
(idgen 0 '())))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment