-
Notifications
You must be signed in to change notification settings - Fork 2
namespaces
A namespace is a structure that holds some stuff, and a list of symbols. Think of it as a folder of commands. That really is about the extent of it. They cannot be nested currently. Could be nice though.
When a namespace is created the python functions are imported directly into it, The module's spr code is also run, and the yaml code associated with the import module will be integrated into the yaml datastore tree.
It is in this way, that spr extensions or applications can exist as python modules on pypi. Even if they do not contain python code. Although they can contain yaml, spr and python code as needed. SPR will try to find yaml and spr files named after the module.
It is encouraged that the modules imported into the namespace have a help()
function. The new-spr-extension-project creates a nice template accordingly.
If there is no python code needed, help text can be set as data.
At a minimum, creating a namespace requires a documentation string. If a help function exists in the namespace that help will be integrated into the namespace help formatting.
-
lswill list all the namespaces. -
ls namewill list the contents of that namespace. -
help namewill show the namespace help, which includes the YAML, and spr code. As well as the SPR help for each symbol. -
pyhelp namewill show the python module help for the module imported into that namespace on it's creation. -
ns-treewill list all the namespaces with their contents. -
importwill import a python module -
nswill tell you which namespace you are in. -
in-nswill move you to another namespace. - which only matters for def, partial, and import. -
new-nscreates a new empty namespace and switches to it. -
namespaceCreates a namespace from a set of python and spr files.
Creating a namespace called foo from a python module foo.core looks like this:
namespace foo "my foo namespace that does bar"
foo.core
function1 function2 ...`
or if it is just a simple spr file that needs to put it's stuff somewhere. Here is an example from t5.spr in the examples.
# namespace for extra particle io board stuff.
new-ns pioe "A few extra particle io board functions" Particle.io-extras.
After a namespace command, the interpreter will remain in that namespace
until it is changed with the in-ns command.
While in a namespace it is also possible to do an import of a python module
like this, which is actually how SPR gets the new_spr_extension_project command,
into it's root namespace. in-ns with no name will take the you to the root
namespace.
in-ns
import Simple_Process_REPL.mkext new_spr_extension_project
SPR files can be loaded with load-file.
`load-file foo.spr`