From 74526784afe52df81769ce3212d809f9c24b79f0 Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Wed, 16 May 2018 11:14:07 -0700 Subject: [PATCH] Add find-var to lumo Now that we have eval, we can easily provide find-var at the REPL. --- CHANGELOG.md | 1 + src/cljs/snapshot/lumo/repl.cljs | 6 ++++++ src/js/cljs.js | 2 +- src/test/lumo/lumo/repl_tests.cljs | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad3faeab..44cb59fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### New features - Allow omitting version in -D – default to the latest locally available version ([#320](https://github.com/anmonteiro/lumo/issues/320)). +- Add `find-var` to `lumo` ([#406](https://github.com/anmonteiro/lumo/pull/406)). ### Bug fixes diff --git a/src/cljs/snapshot/lumo/repl.cljs b/src/cljs/snapshot/lumo/repl.cljs index 5ba98ced..ef3d5e0f 100644 --- a/src/cljs/snapshot/lumo/repl.cljs +++ b/src/cljs/snapshot/lumo/repl.cljs @@ -858,6 +858,12 @@ (vreset! result value)))) @result))) +(defn find-var + "Returns the global var named by the namespace-qualified symbol, or + nil if no var with that name." + [sym] + (eval `(~'var ~sym))) + (defn- intern ([ns name] (intern ns name nil)) diff --git a/src/js/cljs.js b/src/js/cljs.js index 40aa6c4a..8f087050 100644 --- a/src/js/cljs.js +++ b/src/js/cljs.js @@ -544,7 +544,7 @@ async function startClojureScriptEngine(opts: CLIOptsType): Promise { } execute( - "(require '[lumo.repl :refer [apropos find-doc] :refer-macros [dir doc source]])", + "(require '[lumo.repl :refer [apropos find-doc find-var] :refer-macros [dir doc source]])", 'text', true, false, diff --git a/src/test/lumo/lumo/repl_tests.cljs b/src/test/lumo/lumo/repl_tests.cljs index 3006744a..ffdb546e 100644 --- a/src/test/lumo/lumo/repl_tests.cljs +++ b/src/test/lumo/lumo/repl_tests.cljs @@ -208,3 +208,8 @@ Special Form (is (= 3 (core/eval (list + 1 2)))) (is (= 17 (core/eval '(let [a 10] (+ 3 4 a))))) (is (= 5 ((eval (eval '+)) 2 3))))) + +(when test-util/lumo-env? + (deftest test-find-var + (is (= #'cljs.core/map (lumo/find-var 'map)) "it should find function vars") + (is (= #'lumo.repl/*pprint-results* (lumo/find-var 'lumo.repl/*pprint-results*)) "it should find a var in another namespace")))