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))) |
(array-mac Vector3 a b c)
expands to
(clojure.core/let
[^UnityEngine.Vector3[] array_669 (clojure.core/make-array Vector3 3)]
(clojure.core/aset array_669 0 a)
(clojure.core/aset array_669 1 b)
(clojure.core/aset array_669 2 c)
array_669)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For when you find yourself writing something like
(into-array Vector3 [a b c])