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

Add find-var to lumo #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)).

### Changes

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")))