Skip to content

Commit

Permalink
[babashka#420] Add support for clojure.core/find-var
Browse files Browse the repository at this point in the history
  • Loading branch information
RickMoynihan committed Sep 21, 2020
1 parent 2f3760e commit b76d89c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/sci/impl/namespaces.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{:no-doc true}
(:refer-clojure :exclude [ex-message ex-cause eval read
read-string require
use load-string])
use load-string
find-var])
(:require
#?(:clj [clojure.edn :as edn]
:cljs [cljs.reader :as edn])
Expand Down Expand Up @@ -514,6 +515,12 @@
:cljs js/Error)
(str "Not a qualified symbol: " sym))))))

(defn sci-find-var [sci-ctx sym]
(let [namespace (-> sym namespace symbol)
sym' (-> sym name symbol)]
(-> sci-ctx :env deref :namespaces (get-in [namespace sym']) ))
)

;;;; End require + resolve

;;;; Binding vars
Expand Down Expand Up @@ -772,6 +779,7 @@
'ex-message (copy-core-var ex-message)
'ex-cause (copy-core-var ex-cause)
'find-ns (with-meta sci-find-ns {:sci.impl/op :needs-ctx})
#?@(:clj ['find-var (with-meta sci-find-var {:sci.impl/op :needs-ctx})])
'first (copy-core-var first)
'float? (copy-core-var float?)
'floats (copy-core-var floats)
Expand Down
3 changes: 3 additions & 0 deletions test/sci/namespaces_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
(is (eval* "(defn bar []) (ns-unmap *ns* 'bar) (nil? (resolve 'bar))"))
(is (eval* "(defn- baz []) (ns-unmap *ns* 'baz) (nil? (resolve 'baz))")))

(deftest find-var-test
(is (eval* "(= #'clojure.core/map (find-var 'clojure.core/map))")))

(deftest find-ns-test
(is (true? (eval* "(ns foo) (some? (find-ns 'foo))")))
(is (nil? (eval* "(find-ns 'foo)"))))
Expand Down

0 comments on commit b76d89c

Please sign in to comment.