Bug fixing
This commit is contained in:
parent
c6f4b7d041
commit
3257561937
2 changed files with 10 additions and 22 deletions
|
|
@ -111,29 +111,18 @@
|
|||
:cljs [k# v#]
|
||||
:cljd (MapEntry k# v#))] ~@body)))))
|
||||
(not (arities 2)) (conj (let [[[acc karg varg] & body] (arities 3)]
|
||||
`([~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))]
|
||||
`([~acc [~karg ~varg]] ~@body))))]
|
||||
`(reify
|
||||
#?@(:bb [] ;; babashka currently only supports reify with one Java interface at a time
|
||||
:default [~@(macros/case :cljd '[cljd.core/Fn] :clj '[clojure.lang.Fn])])
|
||||
KvRfable
|
||||
(some-kvrf [this#] this#)
|
||||
(~'some-kvrf [this#] this#)
|
||||
~(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]
|
||||
(let [nohint-args (map (fn [arg] (if (:tag (meta arg)) (gensym 'arg) arg)) args)
|
||||
rebind (mapcat (fn [arg nohint]
|
||||
(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)))))))
|
||||
|
||||
(defmacro ^:private let-complete [[binding volatile] & body]
|
||||
|
|
|
|||
|
|
@ -92,10 +92,10 @@
|
|||
(defn avg
|
||||
"Reducing fn to compute the arithmetic mean."
|
||||
([] 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))))
|
||||
([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]))]
|
||||
(doto acc
|
||||
(aset 0 (+ (aget acc 0) w))
|
||||
|
|
@ -137,11 +137,10 @@
|
|||
([sb] (or-instance? #?(:cljd StringBuffer :clj StringBuilder :cljs StringBuffer) sb
|
||||
(#?(:cljd StringBuffer :clj StringBuilder. :cljs StringBuffer.) (core/str sb))))
|
||||
; the instance? checks are for compatibility with str in case of seeded reduce/transduce.
|
||||
([sb x] (#?(:cljd .write :default .append)
|
||||
(or-instance?
|
||||
([sb x] (doto (or-instance?
|
||||
#?(:cljd StringBuffer :clj StringBuilder :cljs StringBuffer) sb
|
||||
(#?(:cljd StringBuffer :clj StringBuilder. :cljs StringBuffer.) (core/str sb)))
|
||||
x)))
|
||||
(#?(:cljd .write :default .append) x))))
|
||||
|
||||
(def str
|
||||
"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