Fix Script {R}←{X}⎕FIX Y

⎕FIX establishes Namespaces, Classes, Interfaces and functions from the script specified by Y in the workspace.

In this section, the term namespace covers scripted Namespaces, Classes and Interfaces.

Y may be a simple character vector, or a vector of character vectors or character scalars. The value of X determines what Y may contain.

If Y is a simple character vector, it must start with "file://", followed by the name of a file which must exist. The contents of the file must follow the same rules that apply to Y when Y is a vector of character vectors or scalars. The file name can be relative or absolute; when considering cross-platform portability, using "/" as the directory delimiter is recommended, although "\" is also valid under Windows.

If specified, X must be a numeric scalar. It may currently take the value 0, 1 or 2. If not specified, the value is assumed to be 1.

If X is 0, Y must specify a single valid namespace which may or may not be named, or a file containing such a definition. If so, the shy result R contains a reference to the namespace. Even if the namespace is named, it is not established per se, although it will exist for as long as at least one reference to it exists.

If X is 1, Y must specify a single valid namespace which may or may not be named, or a file containing such a definition. If so, the shy result R contains a reference to the namespace. If Y contains the definition of a named namespace, the namespace is established in the workspace.

If X is 2, Y is either a character vector containing the name of a script file, or a vector of character vectors that represents a script.

Y may specify a series of named namespaces or function definitions, or a combination of functions and namespaces.

In this case, the shy result R is a vector of character vectors, containing the names of all of the objects that have been established in the workspace; the order of the names in R is not defined. Currently 2 ⎕FIX is not certain to be an atomic operation, although this might change in future versions.

Example 1

In the first example, the Class specified by Y is named (MyClass) but the result of ⎕FIX is discarded. The end-result is that MyClass is established in the workspace as a Class.

      ⎕←⎕FIX ':Class MyClass' ':EndClass'
#.MyClass

Example 2

In the second example, the Class specified by Y is named (MyClass) and the result of ⎕FIX is assigned to a different name (MYREF). The end-result is that a Class named MyClass is established in the workspace, and MYREF is a reference to it.

      MYREF←⎕FIX ':Class MyClass' ':EndClass'
      )CLASSES
MyClass MYREF
      ⎕NC'MyClass' 'MYREF'
9.4 9.4
      MYREF
#.MyClass
      MYREF≡MyClass
1

Example 3

In the third example, the left-argument of 0 causes the named Class MyClass to be visible only via the reference to it (MYREF). It is there, but hidden.

      MYREF←0 ⎕FIX ':Class MyClass' ':EndClass'
      )CLASSES
MYREF
      MYREF
#.MyClass

Example 4

The fourth example illustrates the use of un-named Classes.

      src←':Class' '∇Make n'
      src,←'Access Public' 'Implements Constructor'
      src,←'⎕DF n' '∇' ':EndClass'
      MYREF←⎕FIX src
      )CLASSES
MYREF
      MYINST←⎕NEW MYREF'Pete'
      MYINST
Pete

Example 5

In the final example, the left argument of 2 allows a script containing multiple objects to be fixed:

      src←':Namespace andys' '∇foo' '2' '∇'
      src,←':EndNamespace' 'dfn←{⍺ ⍵}' '∇r←tfn'
      src,←'r←33' '∇' ':Class c1' '∇goo' '1'
      src,←'∇' ':EndClass'
      ≢⎕←2⎕fix src
 c1  tfn  dfn  andys 
4

Restriction

⎕FIX is unable to fix a namespace from Y when Y specifies a multi-line dfn which is preceded by a (diamond separator).

      ⎕FIX':Namespace iaK' 'a←1 ⋄ adfn←{' '⍵' ' }' ':EndNamespace'
DOMAIN ERROR: There were errors processing the script
      ⎕FIX':Namespace iaK' 'a←1 ⋄ adfn←{' '⍵' ' }' ':EndNamespace'
      ∧