importapldyalog

How to Import an APL namespace?


Let's say I have the following namespace in the APL file F.apln:

:Namespace F
foo←{...}
:Endnamespace

I want to import this namespace in another namespace and use it. For example:

IMPORT F

:Namespace G
foo2←F.foo∘÷
:Endnamespace

How?


Solution

  • It depends on what exactly you're trying to do.

    Adjacent namespaces

    :Require file://F.apln
    
    :Namespace G
    foo2←##.F.foo∘÷
    :Endnamespace
    

    Note the ##. which is necessary to reach out of G as the two namespaces are siblings in the namespace hierarchy.

    Nested namespaces

    :Namespace G
    ⎕FIX'file://F.apln'
    foo2←F.foo∘÷
    :Endnamespace
    

    Amend the path to F.apln if the file isn't in the current directory.

    When you do not control the order of loading files (e.g. using Link)

    :Namespace G
    ∇ foo2←foo2
      foo2←##.F.foo∘÷
    
    :Endnamespace
    

    Here, we wrap foo2 in a tradfn so the evaluation of the ##.F reference is deferred to run time.