Use unchecked-aget/aset in with-let macro

This commit is contained in:
Juho Teperi 2018-04-19 19:35:40 +03:00
parent b8f80f56f9
commit f2622f1544
1 changed files with 21 additions and 2 deletions

View File

@ -14,6 +14,25 @@
(deref co#)
co#))
; taken from cljs.core
; https://github.com/binaryage/cljs-oops/issues/14
(defmacro unchecked-aget
([array idx]
(list 'js* "(~{}[~{}])" array idx))
([array idx & idxs]
(let [astr (apply str (repeat (count idxs) "[~{}]"))]
`(~'js* ~(str "(~{}[~{}]" astr ")") ~array ~idx ~@idxs))))
; taken from cljs.core
; https://github.com/binaryage/cljs-oops/issues/14
(defmacro unchecked-aset
([array idx val]
(list 'js* "(~{}[~{}] = ~{})" array idx val))
([array idx idx2 & idxv]
(let [n (dec (count idxv))
astr (apply str (repeat n "[~{}]"))]
`(~'js* ~(str "(~{}[~{}][~{}]" astr " = ~{})") ~array ~idx ~idx2 ~@idxv))))
(defmacro with-let [bindings & body]
(assert (vector? bindings)
(str "with-let bindings must be a vector, not "
@ -27,8 +46,8 @@
x
(let [j (quot i 2)]
`(if ~init
(aset ~v ~j ~x)
(aget ~v ~j)))))
(unchecked-aset ~v ~j ~x)
(unchecked-aget ~v ~j)))))
bindings))
[forms destroy] (let [fin (last body)]
(if (and (list? fin)