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

送分小仙女□ 提交于 2019-12-07 17:16:51

问题


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.


回答1:


  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




回答2:


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 ⍺⍺
}


来源:https://stackoverflow.com/questions/58299517/how-to-build-own-each-operator-using-rank-operator-in-dyalog-apl

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