How to build own Each operator using Rank operator in Dyalog APL

喜欢而已 提交于 2019-12-05 19:20:21
  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

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 ⍺⍺
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!