﻿⍝ Futures and Isolate scripts
⍝ Part 1 - Isolate is a Namespace
)load isolate
⍝ Create and empty namespace and populate it
ns1←⎕NS ''     ⍝ create empty namespace
ns1.x←1 2 3
ns1.(x+1)
ns1.(+/x÷≢x)   ⍝ mean of x
⍝ Create an empty isolate...
is1←ø ''       ⍝ ø ←→ ¤ ←→ isolate.New
is1←isolate.New '' ⍝ Alternate spelling
is1.x←4 5 6 7
is1.(+/x÷≢x)   
is1.(avg←{(+/⍵)÷≢⍵})
is1.(avg x)
is1.(⎕FX ,⊂'avg←{(+/⍵)÷≢⍵}')
⍝ Exercise 1a
ns1.(avg←{(+/⍵)÷≢⍵})
is1←isolate.New ns1 ⍝ Clone ns1 as an isolate
is1.(avg x)
⎕FX 'r←mean x' 'r←(+⌿ ÷ ≢) x'
data←1 2 3 4
mean data
is2←isolate.New 'mean' 'data'
is2.(mean data)
ws←(+2 ⎕NQ '.' 'GetEnvironment' 'DYALOG'),'ws\dfns.dws'
ws
is3←isolate.New ws ⍝ Isolate from workspace
is3.(fibonacci¨⍳20)
⍝ Exercise 1b
iss←ø¨ 3⍴ns1 ⍝ THREE clones of ns1
iss
]boxing on
iss.x
⎕←data←?3 4⍴100 ⍝ "big data" :-)
↓data
iss.x←↓data
iss.x
iss.(x+1)
iss.x+1
iss.(avg x)
iss.x←↓?3 1000000⍴100 ⍝ bigger data
iss.(avg x)
⍝ Parallel execution is cool. "Asynch" is also useful:
twelve←is1.⎕DL 12
2+2
4×3
twelve
)erase is1 is2 is3 twelve
⍝ Exercise 1c