BQN Modules
BQN modules are documented in Namespaces and System scripts, with a single importing function in •Import which returns a namespace, plus •state which tells the module about itself and about its parameters - a strangely uncommon feature.
Consider this single-line module:
Greet ⇐ •args.prefix⊸∾ ∾⟜•args.suffix
And this use of it:
⟨HW⇐Greet⟩ ← {prefix⇐"Hello, ", suffix⇐"!"} •Import "greeter.bqn"
{greet⇐}
⟨GB⇐Greet⟩ ← {prefix⇐"Good bye, ", suffix⇐"."} •Import "greeter.bqn"
{greet⇐}
(HW ⋈ GB) "world"
⟨ "Hello, world!" "Good bye, world." ⟩
That demonstrates selective renaming imports into the current namespace. Some other ways to import:
# direct use without any new bindings
(opts •Import "greeter.bqn").Greet "world"
"Hello, world!"
# binding the namespace and using its contents explicitly
hw ← opts •Import "greeter.bqn"
{greet⇐}
hw.Greet "world"
"Hello, world!"
# selective import without renaming
⟨Greet⟩ ← opts •Import "greeter.bqn"
{greet⇐}
Greet "world"
"Hello, world!"
There's also flexibility in exports. Note that both imports and exports work the same with any namespace:
x‿y ← {⟨x, y⟩⇐ ⋄ x‿y ← 4‿5}
x‿y
^ right-click