Add `module/value` function to make grabbing bindings out module tables.

This commit is contained in:
Calvin Rose 2022-05-05 19:23:41 -05:00
parent fe7d35171f
commit 487d333024
2 changed files with 41 additions and 25 deletions

View File

@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file.
## Unreleased - ???
- Add `module/value`.
- Remove `file/popen`. Use `os/spawn` with the `:pipe` options instead.
- Fix bug in peg `thru` and `to` combinators.
- Fix printing issue in `doc` macro.

View File

@ -2717,6 +2717,21 @@
circular dependencies.`
@{})
(defn module/value
``Given a module table, get the value bound to a symbol `sym`. If `private` is
truthy, will also resolve private module symbols. If no binding is found, will return
nil.``
[module sym &opt private]
(def entry (get module sym))
(if entry
(let [v (in entry :value)
r (in entry :ref)
p (in entry :private)]
(if p (if private nil (break)))
(if (and r (array? r))
(get r 0)
v))))
(defn dofile
``Evaluate a file, file path, or stream and return the resulting environment. :env, :expander,
:source, :evaluator, :read, and :parser are passed through to the underlying