-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
∆NS.aplf
51 lines (45 loc) · 2.37 KB
/
∆NS.aplf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
∆NS←{ ⍝ ⎕NS ─ allows name-value pairs, names values, and ref left arg
⍝ LEFT ARG specifies what target to populate:
⍝ (nothing) ⍝ a new unnamed ns
⍝ ref ⍝ an existing namespace
⍝ name ⍝ a namespace of this name (create if missing)
⍝ RIGHT ARG specifies what to put into the target:
⍝ (empty vector) ⍝ nothing
⍝ name1 ⍝ copy "name1" from the calling space
⍝ name1 name2 ⍝ copy "name1" and "name2" from the calling space
⍝ ↑name1 name2 ⍝ copy "name1" and "name2" from the calling space
⍝ ⊂name1 ⍝ copy "name1" from the calling space
⍝ ⊂name1 value1 ⍝ "name1" with the value "value1"
⍝ (name1 value1)name2 ⍝ "name1" with the value "value1" and copy "name2" from the calling space
⍝ (name1 value1)(⊂name2) ⍝ "name1" wit the value "value1" and copy name2 from the calling space
⍝ (name1 value1)(name2 value2) ⍝ "name1" with the value "value1" and "name2" with the value "value2"
⍝ (↑name1 value1)(name2 value2) ⍝ "name1" with the value "value1" and "name2" with the value "value2"
⍝ RESULT:
⍝ shy name if left arg is name
⍝ not-shy ref otherwise
⎕ML←1
⍺←⊢ ⍝ default to unnamed namespace
Return←{_←⍕⍵}⍣(2∊⎕NC'⍺') ⍝ shy string?
parent←⊃⎕RSI
NS←parent.⎕NS
On←{
String ⍵:⍵ ⍺⍺ ⍺⍎⍵
String↑⍵:⍺(⊢⍺⍺⍎)↑⍵
⍺⍺/⍵
}
Ref←(326=⎕DR)∧0=≡
_∆NS←{
0=⍺⍺.⎕NC'⍺':⍵ ∇⍨NS ⍬ ⍝ ensure dyadic
Char ⍺:⍵ ∇⍨⍺⍺⍎⍺⊣⍺ NS ⍬ ⍝ ensure ref
0=≢⍵:⍺ ⍝ nothing to set
∧/2=≢¨⍵(⍴⊃⍵):⍺ ∇⊃{↓⍉↑(↓⍺)⍵}/⍵ ⍝ ensure name-value pairs
2=≢⍴⍵:⍺ ∇↓⍵ ⍝ ensure name list
(String¨∧.∨Ref)⊆⍵:⍺⊣'ns'⎕NS ⍵⊣ns←⍺ ⍝ named ns
Assign←⍺.{
0 2 9∊⍨⎕NC ⍺:⍎⍺,'←⍵'
⎕SIGNAL⊂('EN' 6)('ENX' 7)('Message'('Can''t change nameclass on assignment: ',⍺))
}
⍺⊣⍺⍺ Assign On¨⊂⍣(2=|≡⍵)⊢⍵
}
Return ⍺(parent _∆NS)⍵
}