3

I saw answer in this question How to use rank operator instead of each in APL how to build own Each operator using Rank .

Monadic Each f¨x can be represented as {⊂f⊃⍵}⍤0⊢x

Dyadic Each x f¨y can be represented as x{⊂(⊃⍺)f(⊃⍵)}⍤0⊢y

In terms of this please answer following questions:

  1. Why Each ¨ operator can be represented as
    Each←{⍺←⊢ ⋄ ⍺ ⍺⍺{×⎕NC'⍺':⊂(⊃⍺)⍺⍺(⊃⍵) ⋄ ⊂⍺⍺⊃⍵}⍤0⊢⍵}
  2. What means ⍺⍺ in the expression above

Thank you in advance for your answers.

2 Answers2

3
  1. This definition basically combines the monadic and dyadic cases which you listed above. ×⎕NC'⍺' will return 1 if exists and 0 otherwise, so it checks if you used Each monadically or dyadically.

  2. ⍺⍺ is the left operand of the dop Each. It is the f in x f Each y or f Each y

RikedyP
  • 632
  • 4
  • 8
1

Here is the same combined operator in a more verbose form, with comments:

Each←{  ⍝ Monadic operator; ⍺⍺ is the operand function
    ⍺←⊢  ⍝ If called monadically ⍺ won't do anything (it will be the no-op function)
    Apply←{  ⍝ This operator applies its operand function (⍺⍺) to disclosed argument(s)
             ⍝ and encloses the result
        ×⎕NC'⍺': ⊂ (⊃⍺) ⍺⍺ (⊃⍵)  ⍝ if we have a left argument, apply ⍺⍺ dyadically (enclose both)
                 ⊂      ⍺⍺ (⊃⍵)  ⍝ otherwise, apply ⍺⍺ just on the enclosed ⍵
    }
    ⍝ Now we're ready to apply to separate elements:
    ⍺ ( (⍺⍺ Apply)⍤0 ) ⍵  ⍝ Even though we have ⍺ here, it may be ⊢ causes a monadic call to ⍺⍺
}
Adám
  • 6,573
  • 20
  • 37