namespace

Command: namespace


Description

"namespace" provides to SLI the concept of namespaces
as known from C++.

The command changes the current scope to the namespace of the given
name i.e.
- all following symbol definitions go to this namespace
- all symbols that were previously defined in this namespace become
known
The namespace must be closed by an "end" statement.

The symbols defined in a namespace persist across closing and
re-opening of the namespace. Namespaces can be nested.

For alternative ways of accessing a namespace
see "using" and "call".

Parameters

/name - the namespace to open

Author

Ruediger Kupper

Availability
SLI2.0

Synopsis

/name namespace ...your.code... end -> -

References

[1] Ruediger Kupper SLI library management
HRI-EU Report 06/05 Honda Research Institute Europe GmbH 2006.

Examples

/myspace namespace % this opens namespace "myspace"
/var 23 def % this creates the variable "myspace::var"
/func {(This is stupid.) =} def % this creates the function "myspace::func"
end % this closes the namespace "myspace"

/myspace namespace % this re-opens the namespace "myspace"
who % this shows the variables defined in the namespace
end % this closes the namespace "myspace"

myspace /func call % this calls "myspace::func"

File
lib/sli/library.sli
Diagnostics

If the named object is not a dictionary TypeMismatchError is raised.

Remarks

Currently namespaces are implemented as
dictionaries. Namespaces may become more tightly
integrated with the SLI interpreter in future.
The idea is to define a set of symbols not in the global user
dictionary but in a separate dictionary that has the name of the
namespace. Thus symbols in different namespaces can have
identical names and are effectively disambiguated by the current
dictionary context.
Note that the namespace dictionary is looked up and created in the
current scope. This is to allow for nested namespaces.

FirstVersion