ref ← ##.mns defn                    ⍝ Make Namespace from association list ⍵.

[defn]  is  a "name association list" of the form ('name' class value), ···. The
result is a reference to a new namespace in which each name in the list has been
instantiated with its given class. The list may contain nested items with class=
9 to represent sub-spaces.  The [mns] function was suggested by Paul Mansour.

Michael Baas suggests that  if [class] is omitted  it should default to 2, which
makes dealing with ⎕JSON data easier.

Technical note:

As  [mns]  is a utility function, it should be able to operate in an environment
with either index origin.  However, the code may not localise and specify ⎕IO as
its value would be inherited by the namespaces it created.  For this reason, the
code is written in an origin-independent way.

Examples:

    alist                                   ⍝ association list
┌─────────────┬────────────────────────────────────────────────────┬─────────────────────┐
│┌───┬─┬─────┐│┌───┬─┬────────────────────────────────────────────┐│┌────┬─┬────────────┐│
││mat│2│1 2 3│││sub│9│┌───────────────────┬──────────────────────┐│││spin│3│┌──────────┐││
││   │ │4 5 6│││   │ ││┌───┬─┬───────────┐│┌────┬─┬─────────────┐││││    │ ││spin←{⍉¨⍵}│││
│└───┴─┴─────┘││   │ │││dup│3│┌─────────┐│││oper│4│┌───────────┐│││││    │ │└──────────┘││
│             ││   │ │││   │ ││dup←{⍵ ⍵}││││    │ ││oper←{⍺⍺ ⍵}│││││└────┴─┴────────────┘│
│             ││   │ │││   │ │└─────────┘│││    │ │└───────────┘││││                     │
│             ││   │ ││└───┴─┴───────────┘│└────┴─┴─────────────┘│││                     │
│             ││   │ │└───────────────────┴──────────────────────┘││                     │
│             │└───┴─┴────────────────────────────────────────────┘│                     │
└─────────────┴────────────────────────────────────────────────────┴─────────────────────┘

    tree mns alist                          ⍝ show fixed ns.
#.[Namespace]
·   ~ mat
·   ∇ spin
·   sub
·   ·   ∇ dup
·   ·   ∘ oper

    (mns alist).(spin sub.(dup oper) mat)   ⍝ check it out.
┌───┬───┐
│1 4│1 4│
│2 5│2 5│
│3 6│3 6│
└───┴───┘

See also: rep

Back to: contents

Back to: Workspaces