Spawn: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Created page with "{| class=vertical-navbox style="float:right; font-size:500%; margin:0 1ex;" |<code>&</code> |} == Spawn == ==== {R}←{X}f&Y ==== & is a monadic operator with an ambivalent...")
(removed the dubble title i added)
Line 2: Line 2:
== Spawn ==
==== {R}←{X}f&Y ====
==== {R}←{X}f&Y ====

Revision as of 01:26, 7 August 2022



& is a monadic operator with an ambivalent derived function. & spawns a new thread in which f is applied to its argument Y (monadic case) or between its arguments X and Y (dyadic case). The shy result of this application is the number of the newly created thread.

When function f terminates, its result (if any), the thread result, is returned.

⎕TSYNC, used monadically, given the thread number can be used to wait for a result from that thread. If no ⎕TSYNC is in effect, the thread result is displayed in the session in the normal fashion.

Note that & can be used in conjunction with the each operator ¨ to launch many threads in parallel.


      ÷&4         ⍝ Reciprocal in background
      ⎕←÷&4       ⍝ Show thread number
      FOO&88      ⍝ Spawn monadic function.
      2 FOO&3     ⍝ dyadic
      {NIL}&0     ⍝ niladic
      ⍎&'NIL'     ⍝ ..
      X.GOO&99    ⍝ thread in remote space.
      ⍎&'⎕dl 2'   ⍝ Execute async expression.
      'NS'⍎&'FOO' ⍝ .. remote .. .. .. 
      PRT&¨↓⎕nl 9 ⍝ PRT spaces in parallel.