Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 4da62ed260
Fetching contributors…

Cannot retrieve contributors at this time

96 lines (76 sloc) 2.439 kB
(in-ns 'clojure.core.typed)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utils
(defmacro defrecord [name slots inv-description invariants & etc]
;only define record if symbol doesn't resolve, not completely sure if this behaves like defonce
(when-not (resolve name)
`(contracts/defconstrainedrecord ~name ~slots ~inv-description ~invariants ~@etc)))
(def third (comp second next))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Constraint shorthands
(def boolean? (some-fn true? false?))
(defn =-c? [& as]
#(apply = (concat as %&)))
(defn every-c? [c]
#(every? c %))
(defn hvector-c? [& ps]
(apply every-pred vector?
(map (fn [p i] #(p (nth % i false))) ps (range))))
(defn array-map-c? [ks-c? vs-c?]
(every-pred #(instance? PersistentArrayMap %)
#(every? ks-c? (keys %))
#(every? vs-c? (vals %))))
(defn hmap-c? [& key-vals]
(every-pred map?
#(every? identity
(for [[k vc] (partition 2 key-vals)]
(and (contains? % k)
(vc (get % k)))))))
(defn hash-c? [ks-c? vs-c?]
(every-pred map?
#(every? ks-c? (keys %))
#(every? vs-c? (vals %))))
(defn set-c? [c?]
(every-pred set?
#(every? c? %)))
(defn sequential-c? [c?]
(every-pred sequential?
(every-c? c?)))
;(defn- comp-mm [mm disps]
; (set/difference disps (set (keys (methods mm)))))
;
;(comp-mm replace-image (disj kinds :scope))
;(comp-mm replace-image (disj kinds :scope))
(declare ^:dynamic *current-env*)
;[Any * -> String]
(defn ^String error-msg
[& msg]
(apply str (when *current-env*
(str (:line *current-env*) ": "))
(concat msg)))
(defn var->symbol [var]
{:pre [(var? var)]
:post [(symbol? %)
(namespace %)]}
(symbol (str (ns-name (.ns ^Var var)))
(str (.sym ^Var var))))
(defn symbol->Class
"Returns the Class represented by the symbol. Works for
primitives (eg. byte, int). Does not further resolve the symbol."
[sym]
{:pre [(symbol? sym)]
:post [(class? %)]}
(case sym
byte Byte/TYPE
short Short/TYPE
int Integer/TYPE
long Long/TYPE
float Float/TYPE
double Double/TYPE
boolean Boolean/TYPE
char Character/TYPE
(Class/forName (str sym))))
(defn Class->symbol [^Class cls]
{:pre [(class? cls)]
:post [(symbol? %)]}
(symbol (.getName cls)))
Jump to Line
Something went wrong with that request. Please try again.