Back
resolve (clj)
(source)function
(resolve sym)
(resolve env sym)
same as (ns-resolve *ns* symbol) or (ns-resolve *ns* &env symbol)
Examples
clojure
(deftest division
(is (= clojure.core// /))
(binding [*ns* *ns*]
(eval '(do (ns foo
(:require [clojure.core :as bar])
(:use [clojure.test]))
(is (= clojure.core// bar//))))))
(deftest namespaced-map-errors
(are [err msg form] (thrown-with-msg? err msg (read-string form))
Exception #"Invalid token" "#:::"
Exception #"Namespaced map literal must contain an even number of forms" "#:s{1}"
Exception #"Namespaced map must specify a valid namespace" "#:s/t{1 2}"
Exception #"Unknown auto-resolved namespace alias" "#::BOGUS{1 2}"
Exception #"Namespaced map must specify a namespace" "#: s{:a 1}"
Exception #"Duplicate key: :user/a" "#::{:a 1 :a 2}"
Exception #"Duplicate key: user/a" "#::{a 1 a 2}"))
(eval (-> "^{:line 42 :column 99} (defn explicit-line-numbering [])" str->lnpr read))
(is (= {:line 42 :column 99}
(-> 'explicit-line-numbering resolve meta (select-keys [:line :column])))))
hoplon/hoplon
(ns hoplon.binding
(:refer-clojure :exclude [binding bound-fn])
(:require [clojure.core :as clj]
[cljs.analyzer :as a]))
(defmacro binding
"See clojure.core/binding."
[bindings & body]
(let [env (assoc &env :ns (a/get-namespace a/*cljs-ns*))
value-exprs (take-nth 2 (rest bindings))
bind-syms (map #(:name (a/resolve-existing-var env %)) (take-nth 2 bindings))
bind-syms' (map (partial list 'quote) bind-syms)
set-syms (repeatedly (count bind-syms) gensym)
setfn (fn [x y]
{:push! `(fn []
(let [z# ~x]
(set! ~x ~y)
(fn [] (set! ~x z#))))})
thunkmaps (map setfn bind-syms set-syms)]
(a/confirm-bindings env bind-syms)
`(let [~@(interleave set-syms value-exprs)]
(hoplon.binding/push-thread-bindings ~(zipmap bind-syms' thunkmaps))
(try ~@body (finally (hoplon.binding/pop-thread-bindings))))))
hraberg/deuce
(ns deuce.emacs.character
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c])
(:refer-clojure :exclude []))
(defun char-resolve-modifiers (char)
"Resolve modifiers in the character CHAR.
The value is a character with modifiers resolved into the character
code. Unresolved modifiers are kept in the value."
)
typedclojure/typedclojure
In general these operations:
- are macros instead of functions
- take Typed Clojure types instead of malli schemas
- helps the type checker infer their results
See also:
- typed.malli.generator
- typed.malli.swagger
- typed.malli.json-schema"
(:require [typed.clojure :as t]
[clojure.core.typed.unsafe :as unsafe]
[malli.core :as m]))
(defmacro validate
"Validate v as type t. Type checker infers as a predicate
on t.
eg.,
(validate t/AnyInteger 1) => true
(validate t/AnyInteger nil) => false"
[t v]
`((unsafe/ignore-with-unchecked-cast
m/validate
[t/Any t/Any :-> t/Bool :filters {:then (~'is ~t 1)
:else (~'! ~t 1)}])
~((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax) t)
~v))
(defmacro validator
"Create validator for type t. Type checker infers as a predicate
on t.
eg.,
((validator t/AnyInteger) 1) => true
((validator t/AnyInteger) nil) => false"
[t]
`((unsafe/ignore-with-unchecked-cast
m/validator
[t/Any :-> [t/Any :-> t/Bool :filters {:then (~'is ~t 0)
:else (~'! ~t 0)}]])
~((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax) t)))
(defmacro explain
"Explain validation failure of v conforming to type t. Type checker infers as a predicate
on \"not t\".
(explain t/AnyInteger 1) => nil
(explain t/AnyInteger nil)
=>
{:schema :int,
:value nil,
:errors
({:path [],
:in [],
:schema :int,
:value nil,
:type nil,
:message nil})}"
[t v]
`((unsafe/ignore-with-unchecked-cast
m/explain
[t/Any t/Any :-> (t/Nilable '{:schema t/Any
:value t/Any
:errors (t/Seqable t/Any)})
:filters {:then (~'! ~t 1)
:else (~'is ~t 1)}])
~((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax) t)
~v))
(defmacro parse
"Parse value v as type t. Type checker infers the shape of
return value.
eg.,
(parse t/AnyInteger 1) ;=> 1
(parse t/AnyInteger nil) ;=> :malli.core/invalid
(parse (t/U ^{::name :int} t/AnyInteger
^{::name :bool} t/Bool)
1)
;=> [:int 1]
(parse (t/U ^{::name :int} t/AnyInteger
^{::name :bool} t/Bool)
true)
;=> [:bool true]"
[t v]
`((unsafe/ignore-with-unchecked-cast
m/parse
[t/Any t/Any :-> (t/U '::m/invalid ~(-> t
((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax))
((requiring-resolve 'typed.malli.schema-to-type/malli-syntax->parser-type))))])
~((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax) t)
~v))
(defmacro parser
"Create parser for Typed Clojure type t. Type checker infers
the type of the return value when used.
eg.,
((parser t/AnyInteger) 1) ;=> 1
((parser t/AnyInteger) nil) ;=> :malli.core/invalid
((parser (t/U ^{::name :int} t/AnyInteger
^{::name :bool} t/Bool))
1)
;=> [:int 1]
((parser (t/U ^{::name :int} t/AnyInteger
^{::name :bool} t/Bool))
true)
;=> [:bool true]"
[t]
`(m/parser ~((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax) t)))
(defmacro defparser
"Def parser for Typed Clojure type t. Type checker infers
the type of the return value when used.
eg.,
(defparser AnyInteger-parser t/AnyInteger)
(AnyInteger-parser 1) ;=> 1
(AnyInteger-parser nil) ;=> :malli.core/invalid"
[name t]
`(do (t/ann ~(vary-meta name assoc :no-check true)
[t/Any :-> (t/U (t/Val ::m/invalid)
~(-> t
((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax))
((requiring-resolve 'typed.malli.schema-to-type/malli-syntax->parser-type))))])
(def ~name (parser ~t))))
(defmacro unparse [t v]
`(m/unparse ~((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax) t)
~v))
(defmacro unparser [t]
`(m/unparser ~((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax) t)))
(defmacro -instrument [tmap & args]
`(m/-instrument ~(update tmap :schema (requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax))
~@args))
(defmacro => [name t]
`(m/=> ~name ~((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax) t)))
typedclojure/typedclojure
(ns typed.clojure.jvm
"JVM-specific annotations and operations.
See typed.clojure for cross-platform ops."
(:require clojure.core.typed
[clojure.core.typed.current-impl :as impl]
[clojure.core.typed.internal :refer [take-when]]
[typed.cljc.runtime.env-utils :refer [delay-type]]
[clojure.core.typed.macros :as macros]))
(defmacro override-class [& args]
(let [[binder args] (take-when vector? args)
[nme args] (take-when symbol? args)
_ (assert (symbol? nme) (str "Missing name in override-class" [nme args]))
[opts args] (take-when map? args)
opts (if opts
(do (assert (empty? args) (str "Trailing args to override-class: " (pr-str args)))
opts)
(apply hash-map args))
this-ns (ns-name *ns*)]
`(clojure.core.typed/tc-ignore
(let [nme# (or (when-some [^Class c# (ns-resolve '~this-ns '~nme)]
(when (class? c#)
(-> c# .getName symbol)))
(throw (ex-info (str "Could not resolve class: " '~nme) {:class-name '~nme})))]
;; TODO runtime env
#_
(impl/add-rclass-env nme# {:op :RClass})
;; type env
;inline when-bindable-defining-ns
(macros/when-bindable-defining-ns '~this-ns
(impl/with-clojure-impl
(impl/add-rclass nme# (delay-type
((requiring-resolve 'typed.clj.checker.parse-unparse/with-parse-ns*)
'~this-ns
#((requiring-resolve 'typed.cljc.checker.base-env-helper/make-RClass)
nme#
'~binder
'~opts))))))))))
athos/kitchen-async
(ns kitchen-async.promise.from-channel
(:require [clojure.core.async :as a]
[clojure.core.async.impl.channels :refer [ManyToManyChannel]]
[kitchen-async.promise :as p]
[kitchen-async.protocols.promisable :refer [Promisable]]))
(extend-protocol Promisable
ManyToManyChannel
(->promise* [c]
(p/promise [resolve reject]
(a/go
(let [x (a/<! c)]
(if (instance? js/Error x)
(reject x)
(resolve x)))))))