Product Site

1.14. Namespaces

Namespaces can be used to differentiate between classes or routines of the same name, having been loaded through ::REQUIRES directives.

Using ::REQUIRES with the NAMESPACE option allows to tag a loaded file with a namespace name, which in turn can be used to qualify references to classes or routines within that namespace to explicitly identify a specific class or routine. A special reserved namespace "REXX" will allow to always access the Rexx-provided classes.

Examples:
Example 1.34. Namespaces
-- disambiguate between two classes with same name
say .number~id                          -- The Real Number class
say natural:number~id                   -- The Natural Number class

-- use reserved namespace "REXX" to get Rexx-defined .Array
-- not :class array as defined below
say rexx:array~of(2, 3, 5, 7)~items     -- 4

-- call ::routine verify, not built-in function
call natural:verify(17)

-- use natural:number as a message target
say natural:number~subclass("Integer")  -- The Integer class


-- subclass natural:number, not ::class number as defined below
::class rationalNumber subclass natural:number

-- class "number"; same name as a class in 'number.cls'
::class number
::method id class
return "The Real Number class"

-- class "Array"; same name as Rexx-defined
::class array

::requires 'number.cls' namespace natural

Example 1.35. number.cls
::class number public
::method id class
return "The Natural Number class"

::routine verify public
return arg(1) >= 0 & arg(1)~dataType("W")