Namespace Objects

The full name of every object consists of a namespace and an object name. Including a namespace in the object name makes it less likely that creating a new object definition in a new library will result in a name collision with another object definition.

Namespaces in Sym are also objects. Users can create new namespaces just by creating an appropriate object definition.

Creating a namespace

Creating a namespace is the same as creating any other object definition except that there are a few additional requirements in order for the new object to be understood to be a namespace. The requirements are:
  1. The object definition must be placed inside of the NamespaceObjects namespace.
  2. The type definition must be Type :: Namespace

See Creating an Object Definition for additional information.

If we open a new Object Module and create a new namespace called MyNamespace in it, we would then have:

Now we can create another namespace, either in the same Object Module or in another Object Module and create a new object in MyNamespace:

The Data namespace

The Data namespace is used when we want a clause to manipulate or return an expression that would normally be executable. For example, in the Convert command there is a clause that converts and Assert object to an AssertList (or vice versa). The Assert or AssertList object on the right-hand side of these clauses in the Convert function would normally be executed.

To avoid having these terms be executed, we first move then to the Data namespace, then apply the code that manipulates the terms in the appropriate way, then move the expression back to the namespace it started in. In the Convert command we call FromData[ConvertCode[ToData[f]]] to accomplish this.

Objects in the Data namespace have the same type definition and renderings as the original object, except for the coloring used to distinguish objects that are in the Data namespace. This is possible because the Data namespace is a one-parameter object that takes a namespace as the parameter.

The original namespace becomes the parameter of the Data namespace in the ToData function. This allows the FromData function to put the expression back in its original namespace and it allows us to find the appropriate type definition and rendering of the object when it's in the Data namespace.

Built in namespaces

There are a number of namespaces that are predefined by Sym:

Namespace Description
Build Objects and functions used in the build process are defined in this namespace.
Code The namespace used for objects that are part of the Sym programming language.
Core Objects that are commonly used but aren't necessarily mathematical objects are defined in this namespace. The At and EmptyBox objects are two examples.
ExecutionDetails The namespace used for defining the objects that appear in the execution details
Internal The namespace used for built in functions
Local The namespace assigned by default when variables like "x" or "y" are created by typing into an empty box in a document section.
Logic The namespace used the Boolean objects
Math The Math namespace is used for all of the normal math objects that are defined in the Math.eql library
NamespaceObjects The namespace for objects that define namespaces
Notations Objects that define Notations are created in the Notations namespace. See Notations - Overview for more information.
Render Objects that are normally only used for rendering are defined in this namespace.
Sym Objects and functions that are need to be built at the beginning of the build process are defined in this namespace. You normally don't want to add anything in this namespace.
Types The namespace used for object types like Object, Real, etc.
Variables The namespace for variables that are used in code in the Sym language. By default, when you type "x" or "y" into an empty box in a clause in an Object Module, the term will be assigned to the Variables namespace.