Last active
August 29, 2015 14:14
-
-
Save timsgardner/1181fb86151e602c3f94 to your computer and use it in GitHub Desktop.
array-mac
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
(defmacro array-mac [t & elements] | |
(let [^Type tt (resolve t) | |
atypesym (symbol (str (.FullName tt) "[]")) | |
asym (gensym "array_") | |
setexprs (->> elements | |
(map-indexed | |
(fn [i x] | |
`(aset ~asym ~i ~x))))] | |
`(let [~(with-meta asym {:tag atypesym}) (make-array ~t ~(count elements))] | |
~@setexprs | |
~asym))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(array-mac Vector3 a b c)
expands to