moar
This commit is contained in:
parent
a24bf88e03
commit
e524cb836f
2 changed files with 15 additions and 9 deletions
|
|
@ -17,7 +17,9 @@
|
||||||
(:refer-clojure :exclude [+ * and assert or cat def keys merge])
|
(:refer-clojure :exclude [+ * and assert or cat def keys merge])
|
||||||
(:require [babashka.impl.clojure.spec.gen.alpha :as gen]
|
(:require [babashka.impl.clojure.spec.gen.alpha :as gen]
|
||||||
[clojure.walk :as walk]
|
[clojure.walk :as walk]
|
||||||
[sci.core :as sci]))
|
[sci.core :as sci]
|
||||||
|
[sci.impl.evaluator :as eval]
|
||||||
|
[babashka.impl.common :refer [ctx]]))
|
||||||
|
|
||||||
(alias 'c 'clojure.core)
|
(alias 'c 'clojure.core)
|
||||||
|
|
||||||
|
|
@ -322,12 +324,14 @@
|
||||||
(conj (walk/postwalk-replace {s '%} form) '[%] 'fn))
|
(conj (walk/postwalk-replace {s '%} form) '[%] 'fn))
|
||||||
expr))
|
expr))
|
||||||
|
|
||||||
|
(defn sci-resolve [sym]
|
||||||
|
(@sci.impl.utils/eval-resolve-state @ctx {} sym))
|
||||||
|
|
||||||
(defn res [form]
|
(defn res [form]
|
||||||
(cond
|
(cond
|
||||||
(keyword? form) form
|
(keyword? form) form
|
||||||
(symbol? form) (c/or
|
(symbol? form) (c/or
|
||||||
;; TODO: insert sci resolve here
|
(-> form sci-resolve ->sym) form)
|
||||||
#_(-> form resolve ->sym) form)
|
|
||||||
(sequential? form) (walk/postwalk #(if (symbol? %) (res %) %) (unfn form))
|
(sequential? form) (walk/postwalk #(if (symbol? %) (res %) %) (unfn form))
|
||||||
:else form))
|
:else form))
|
||||||
|
|
||||||
|
|
@ -343,16 +347,17 @@
|
||||||
(swap! registry-ref assoc k (with-name spec k))))
|
(swap! registry-ref assoc k (with-name spec k))))
|
||||||
k)
|
k)
|
||||||
|
|
||||||
|
(defn sci-ns-aliases []
|
||||||
|
(sci/eval-form @ctx (list 'ns-aliases @sci/ns)))
|
||||||
|
|
||||||
(defn ns-qualify
|
(defn ns-qualify
|
||||||
"Qualify symbol s by resolving it or using the current *ns*."
|
"Qualify symbol s by resolving it or using the current *ns*."
|
||||||
[s]
|
[s]
|
||||||
(if-let [ns-sym (some-> s namespace symbol)]
|
(if-let [ns-sym (some-> s namespace symbol)]
|
||||||
(c/or (some->
|
(c/or (some->
|
||||||
;; TODO: use sci ns-aliases
|
(get (sci-ns-aliases) ns-sym) str (symbol (name s)))
|
||||||
(get (ns-aliases *ns*) ns-sym) str (symbol (name s)))
|
|
||||||
s)
|
s)
|
||||||
;; TODO: use sci current-ns!
|
(symbol (str @sci/ns) (str s))))
|
||||||
(symbol (str (.name *ns*)) (str s))))
|
|
||||||
|
|
||||||
(defmacro def
|
(defmacro def
|
||||||
"Given a namespace-qualified keyword or resolvable symbol k, and a
|
"Given a namespace-qualified keyword or resolvable symbol k, and a
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns babashka.impl.common)
|
(ns babashka.impl.common
|
||||||
|
(:require [sci.core :as sci]))
|
||||||
|
|
||||||
;; placeholder for ctx
|
;; placeholder for ctx
|
||||||
(def ctx (volatile! nil))
|
(def ctx (volatile! (sci/init {})))
|
||||||
(def bb-edn (volatile! nil))
|
(def bb-edn (volatile! nil))
|
||||||
(def debug (volatile! false))
|
(def debug (volatile! false))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue