*current-file* (keyword)
*current-file* is bound to the keyword :current-file—it provides a
global alias to the dynamic binding containing the path of the currently
compiling file.
repl> (root-env '*current-file*)
@{:doc "Bound to the name of the currently compiling file."
:dyn true
:source-map ("boot.janet" 1343 1)
:value :current-file}
Things I Learned
- Dynamic bindings are just keyword/value pairs in the current fiber’s environment.
- As a consequence, some standard library functions (e.g.,
run-context), that operate on a provided environment use(put env key val)rather thansetdynto set dynamic values. - By contrast,
setdynis implemented as a C function that essentially performs the equivalentputoperation on the current fiber’s environment via direct access to the VM and fiber data structures (presumably for performance).