Skip to content

Distributed Assignment

Assignment pervades nested strands of names to the left of the arrow. The conformability rules are the same as for scalar (pervasive) dyadic primitive functions such as '+'. The mechanism can be viewed as a way of naming the parts of a structure.

Examples

      EMP.(FirstName Age)
  JOHN  43   PAUL  44

      EMP.(FirstName Age)('Jonathan' 21)('Pauline' 22)

      EMP.(FirstName Age)
  Johnathan  21   Pauline  22

⍝ Distributed assignment is pervasive
      JOHN.Children.(FirstName Age)
  Andy  23   Katherine  19

      JOHN.Children.(FirstName Age)('Andrew' 21)('Kate' 9)

      JOHN.Children.(FirstName Age)
  Andrew  21   Kate  9

More Examples

      ((a b)(c d))(1 2)(3 4)   ⍝ a←1 ⋄ b←2 ⋄ c←3 ⋄ d←4

      ((⎕io ⎕ml)vec)0 ⎕av      ⍝ ⎕io←0 ⋄ ⎕ml←0 ⋄ vec←⎕av

      (i (j k))+1 2            ⍝ i+←1 ⋄ j+←2 ⋄ k+←2

⍝ Naming of parts:

      ((first last) sex (street city state))npvec

⍝ Distributed assignment in :For loop:

      :For (i j)(k l) :In array

⍝ Ref array expansion:

      (x y).(first last)('John' 'Doe')('Joe' 'Blow')
      (f1 f2).(b1 b2).Caption'OK' 'Cancel'

⍝ Structure rearrangement:
      rotate1{       ⍝ Simple binary tree rotation.
           (a b c)d e
           a b(c d e)
      }
      rotate3{       ⍝ Compound binary tree rotation.
           (a b(c d e))f g
           (a b c)d(e f g)
      }