Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
Add find-var to lumo
Browse files Browse the repository at this point in the history
Now that we have eval, we can easily provide find-var at the REPL.
  • Loading branch information
arichiardi committed May 25, 2018
1 parent 2b4bc09 commit 7452678
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/cljs/snapshot/lumo/repl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/js/cljs.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ async function startClojureScriptEngine(opts: CLIOptsType): Promise<mixed> {
}

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,
Expand Down
5 changes: 5 additions & 0 deletions src/test/lumo/lumo/repl_tests.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))

0 comments on commit 7452678

Please sign in to comment.