You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/runtime.rst
+21Lines changed: 21 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -111,6 +111,27 @@ This is roughly analogous to the Java classpath in Clojure.
111
111
These values may be set manually, but are more often configured by some project management tool such as Poetry or defined in your Python virtualenv.
112
112
These values may also be set via :ref:`cli` arguments.
113
113
114
+
Requiring Code Dynamically
115
+
##########################
116
+
117
+
The Basilisp compiler attempts to verify the existence of Vars and Python module members during its analysis phase.
118
+
It typically does that by introspecting the runtime environment (Namespaces or Python modules).
119
+
Requiring a namespace in a highly dynamic context (e.g. from within a function call) and then immediately attempting to reference that value prevents the compiler from verifying references (which is an error).
120
+
121
+
.. code-block::
122
+
123
+
((fn []
124
+
(require 'basilisp.set)
125
+
(basilisp.set/difference #{:b} #{:a})))
126
+
;; => error occurred during macroexpansion: unable to resolve symbol 'basilisp.set/difference' in this context
127
+
128
+
In such cases, it may be preferable to use :lpy:fn:`requiring-resolve` to dynamically require and resolve the Var rather than fighting the compiler:
0 commit comments