Skip to content

Commit 57968b6

Browse files
authored
Fix the ns-resolve function to resolve aliased symbols (#313)
* Fix the ns-resolve function to resolve aliased symbols * Remove unnecessary extra var
1 parent 27a866b commit 57968b6

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/basilisp/core/__init__.lpy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@
15391539
(defn ns-resolve
15401540
"Return the Var which will be resolved by the symbol in the given namespace."
15411541
[ns sym]
1542-
(.find ns sym))
1542+
(basilisp.lang.runtime/resolve-var sym ns))
15431543

15441544
(defn resolve
15451545
"Return the Var which will be resolved by the symbol in the namespace currently

src/basilisp/lang/runtime.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,12 @@ def resolve_alias(s: sym.Symbol, ns: Optional[Namespace] = None) -> sym.Symbol:
924924
return sym.symbol(s.name, ns=ns.name)
925925

926926

927+
def resolve_var(s: sym.Symbol, ns: Optional[Namespace] = None) -> Optional[Var]:
928+
"""Resolve the aliased symbol to a Var from the specified
929+
namespace, or the current namespace if none is specified."""
930+
return Var.find(resolve_alias(s, ns))
931+
932+
927933
def add_generated_python(
928934
generated_python: str,
929935
var_name: str = _GENERATED_PYTHON_VAR_NAME,

src/basilisp/repl.lpy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
(defmacro doc
3636
"Print the docstring from an interned Var if found."
3737
[s]
38-
`(print-doc (var ~s)))
38+
`(print-doc (resolve (quote ~s))))
3939

4040
(defn print-source
4141
"Print the source forms for a function."
@@ -45,4 +45,4 @@
4545
(defmacro source
4646
"Print the source code for a form if found."
4747
[s]
48-
`(print-source (var ~s)))
48+
`(print-source (resolve (quote ~s))))

0 commit comments

Comments
 (0)