Bug fixing
This commit is contained in:
parent
c6f4b7d041
commit
3257561937
2 changed files with 10 additions and 22 deletions
|
|
@ -111,30 +111,19 @@
|
||||||
:cljs [k# v#]
|
:cljs [k# v#]
|
||||||
:cljd (MapEntry k# v#))] ~@body)))))
|
:cljd (MapEntry k# v#))] ~@body)))))
|
||||||
(not (arities 2)) (conj (let [[[acc karg varg] & body] (arities 3)]
|
(not (arities 2)) (conj (let [[[acc karg varg] & body] (arities 3)]
|
||||||
`([~acc [~karg ~varg]] ~@body))))
|
`([~acc [~karg ~varg]] ~@body))))]
|
||||||
fn-bodies
|
|
||||||
(core/for [[[acc x :as args] & body :as fn-body] fn-bodies]
|
|
||||||
(if (and (= 2 (core/count args)) (vector? x))
|
|
||||||
`([~acc x#] (let [~x x#] ~@body))
|
|
||||||
fn-body))]
|
|
||||||
`(reify
|
`(reify
|
||||||
#?@(:bb [] ;; babashka currently only supports reify with one Java interface at a time
|
#?@(:bb [] ;; babashka currently only supports reify with one Java interface at a time
|
||||||
:default [~@(macros/case :cljd '[cljd.core/Fn] :clj '[clojure.lang.Fn])])
|
:default [~@(macros/case :cljd '[cljd.core/Fn] :clj '[clojure.lang.Fn])])
|
||||||
KvRfable
|
KvRfable
|
||||||
(some-kvrf [this#] this#)
|
(~'some-kvrf [this#] this#)
|
||||||
~(macros/case :cljs `core/IFn :clj 'clojure.lang.IFn :cljd 'cljd.core/IFn)
|
~(macros/case :cljs `core/IFn :clj 'clojure.lang.IFn :cljd 'cljd.core/IFn)
|
||||||
#_~@(map (fn [[args & body]]
|
|
||||||
(list* 'cljd.core/-invoke (core/into [name] args) body))
|
|
||||||
#_'[([f] 0) ([f a] 1) ([f a b] 2) ([f a b c] 3)]
|
|
||||||
fn-bodies
|
|
||||||
#_(throw (ex-info "CACA" {:dc fn-bodies})))
|
|
||||||
|
|
||||||
~@(core/for [[args & body] fn-bodies]
|
~@(core/for [[args & body] fn-bodies]
|
||||||
(let [nohint-args (map (fn [arg] (if (:tag (meta arg)) (gensym 'arg) arg)) args)
|
(let [nohint-args (map (fn [arg] (if (:tag (meta arg)) (gensym 'arg) arg)) args)
|
||||||
rebind (mapcat (fn [arg nohint]
|
rebind (mapcat (fn [arg nohint]
|
||||||
(when-not (= arg nohint) [arg nohint])) args nohint-args)]
|
(when-not (= arg nohint) [arg nohint])) args nohint-args)]
|
||||||
`(~(macros/case :cljd 'cljd.core/-invoke :cljs `core/-invoke :clj 'invoke)
|
`(~(macros/case :cljd '-invoke :cljs `core/-invoke :clj 'invoke)
|
||||||
[~name ~@nohint-args] ~@(if (seq rebind) [`(let [~@rebind] ~@body)] body)))))))
|
[~name ~@nohint-args] ~@(if (seq rebind) [`(let [~@rebind] ~@body)] body)))))))
|
||||||
|
|
||||||
(defmacro ^:private let-complete [[binding volatile] & body]
|
(defmacro ^:private let-complete [[binding volatile] & body]
|
||||||
`(let [v# @~volatile]
|
`(let [v# @~volatile]
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,10 @@
|
||||||
(defn avg
|
(defn avg
|
||||||
"Reducing fn to compute the arithmetic mean."
|
"Reducing fn to compute the arithmetic mean."
|
||||||
([] nil)
|
([] nil)
|
||||||
([#?(:cljd ^{:tag #/(List double)} acc :clj ^doubles acc :cljs ^doubles acc)]
|
([#?(:cljd ^{:tag #/(List? double)} acc :clj ^doubles acc :cljs ^doubles acc)]
|
||||||
(when acc (/ (aget acc 1) (aget acc 0))))
|
(when acc (/ (aget acc 1) (aget acc 0))))
|
||||||
([acc x] (avg acc x 1))
|
([acc x] (avg acc x 1))
|
||||||
([#?(:cljd ^{:tag #/(List double)} acc :clj ^doubles acc :cljs ^doubles acc) x w]
|
([#?(:cljd ^{:tag #/(List? double)} acc :clj ^doubles acc :cljs ^doubles acc) x w]
|
||||||
(let [acc (or acc #?(:cljd (double-array 2) :clj (double-array 2) :cljs #js [0.0 0.0]))]
|
(let [acc (or acc #?(:cljd (double-array 2) :clj (double-array 2) :cljs #js [0.0 0.0]))]
|
||||||
(doto acc
|
(doto acc
|
||||||
(aset 0 (+ (aget acc 0) w))
|
(aset 0 (+ (aget acc 0) w))
|
||||||
|
|
@ -137,11 +137,10 @@
|
||||||
([sb] (or-instance? #?(:cljd StringBuffer :clj StringBuilder :cljs StringBuffer) sb
|
([sb] (or-instance? #?(:cljd StringBuffer :clj StringBuilder :cljs StringBuffer) sb
|
||||||
(#?(:cljd StringBuffer :clj StringBuilder. :cljs StringBuffer.) (core/str sb))))
|
(#?(:cljd StringBuffer :clj StringBuilder. :cljs StringBuffer.) (core/str sb))))
|
||||||
; the instance? checks are for compatibility with str in case of seeded reduce/transduce.
|
; the instance? checks are for compatibility with str in case of seeded reduce/transduce.
|
||||||
([sb x] (#?(:cljd .write :default .append)
|
([sb x] (doto (or-instance?
|
||||||
(or-instance?
|
#?(:cljd StringBuffer :clj StringBuilder :cljs StringBuffer) sb
|
||||||
#?(:cljd StringBuffer :clj StringBuilder :cljs StringBuffer) sb
|
(#?(:cljd StringBuffer :clj StringBuilder. :cljs StringBuffer.) (core/str sb)))
|
||||||
(#?(:cljd StringBuffer :clj StringBuilder. :cljs StringBuffer.) (core/str sb)))
|
(#?(:cljd .write :default .append) x))))
|
||||||
x)))
|
|
||||||
|
|
||||||
(def str
|
(def str
|
||||||
"Reducing function to build strings in linear time. Acts as replacement for clojure.core/str in a reduce/transduce call."
|
"Reducing function to build strings in linear time. Acts as replacement for clojure.core/str in a reduce/transduce call."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue