【问题标题】:How to build own Each operator using Rank operator in Dyalog APL如何在 Dyalog APL 中使用 Rank 运算符构建自己的每个运算符
【发布时间】:2019-10-09 07:57:48
【问题描述】:

我看到了这个问题的答案How to use rank operator instead of each in APLhow to build own Each operator using Rank .

Monadic 每个f¨x 可以表示为{⊂f⊃⍵}⍤0⊢x

二元每个x f¨y可以表示为x{⊂(⊃⍺)f(⊃⍵)}⍤0⊢y

就此请回答以下问题:

  1. 为什么每个¨ 运算符都可以表示为
    Each←{⍺←⊢ ⋄ ⍺ ⍺⍺{×⎕NC'⍺':⊂(⊃⍺)⍺⍺(⊃⍵) ⋄ ⊂⍺⍺⊃⍵}⍤0⊢⍵}
  2. 上面表达式中的⍺⍺是什么意思

提前感谢您的回答。

【问题讨论】:

    标签: apl dyalog


    【解决方案1】:
    1. 这个定义基本上结合了你上面列出的一元和二元情况。如果 存在,×⎕NC'⍺' 将返回1,否则返回0,因此它会检查您是单次使用还是二元使用Each

    2. ⍺⍺ 是 dop Each 的左操作数。它是x f Each yf Each y 中的f

    【讨论】:

    • Richard, 1. 可以理解,谢谢。 2. 还不清楚。这就是为什么不能得到所有的表达
    【解决方案2】:

    下面是相同的组合运算符,形式更详细,带有 cmets:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多