*args*
(keyword)
*args*
is bound to the keyword :args
—it provides a global alias to
the dynamic binding containing the process’s command line arguments.
repl> (root-env '*args*)
@{:doc "Dynamic bindings that will contain command line arguments at program start."
:dyn true
:source-map ("boot.janet" 4534 1)
:value :args}
Things I Learned
*args*
is used byspork/argparse
to expose a high-level command line argument parsing API.- While Janet has mutable variables (created with
var
) and mutable data structures, the core API does not expose any public, mutable global state. - Janet prefers dynamic bindings to global mutable state.
- It’s conventional to use the
defdyn
macro to create a global alias to a dynamic binding. - Global aliases are desirable because they make the dynamic binding an explicit part of the environment, support metadata and docstrings, and help to prevent typos.
- Binding names surrounded by a single pair of asterisks are known colloquially as "earmuffs". Historically, earmuffs have been used by Lisp dialects to indicate global, mutable state. Janet, breaking from tradition, uses earmuffs to indicate global aliases to dynamic bindings.