Search Path ⎕PATH

⎕PATH is a simple character vector representing a blank-separated list of namespaces.  It is approximately analogous to the PATH variable in Windows or UNIX

The ⎕PATH variable can be used to identify a namespace in which commonly used utility functions reside.  Functions or operators (NOT variables) which are copied into this namespace and exported (see Export Object) can then be used directly from anywhere in the workspace without giving their full path names.

Example

To make the DISPLAY function available directly from within any namespace.

      ⍝ Create and reference utility namespace.
      ⎕PATH←'⎕se.util'⎕ns''
      ⍝ Copy DISPLAY function from UTIL into it.
      'DISPLAY'⎕se.util.⎕cy'UTIL'
      ⍝ (Remember to save the session to file).  

In detail, ⎕PATH works as follows:

When a reference to a name cannot be found in the current namespace, the system searches for it from left to right in the list of namespaces indicated by ⎕PATH.  In each namespace, if the name references a defined function (or operator) and the export type of that function is non-zero (see ⎕EXPORT is used to set or query the export type of a defined function (or operator) referenced by the ⎕PATH mechanism. ), then it is used to satisfy the reference.  If the search exhausts all the namespaces in ⎕PATH without finding a qualifying reference, the system issues a VALUE ERROR in the normal manner.

The special character stands for the list of namespace ancestors:

       ## ##.## ##.##.## ...

In other words, the search is conducted upwards through enclosing namespaces, emulating the static scope rule inherent in modern block-structured languages.

Note that the ⎕PATH mechanism is used ONLY if the function reference cannot be satisfied in the current namespace.  This is analogous to the case when the Windows or UNIX PATH variable begins with a '.'.

 

Examples

   ⎕PATH               Search in ...
1. '⎕se.util'          Current space,   then
                       ⎕se.util,        then
                       VALUE ERROR
 
2. '↑'                 Current space
                       Parent space: ##
                       Parent's parent space:  ##.##
                       ...
                       Root: # (or ⎕se if current space
                                was inside ⎕se)
                       VALUE ERROR
 
3. 'util ↑ ⎕se.util'   Current space
                       util (relative to current space)
                       Parent space: ##
                       ...
                       Root: # or ⎕se
                       ⎕se.util
                       VALUE ERROR

Note that ⎕PATH is a session variable.  This means that it is workspace-wide and survives )LOAD and )CLEAR. It can of course, be localised by a defined function or operator.