如何在 Dyalog APL 中使用 Rank 运算符构建自己的 Each 运算符
How to build own Each operator using Rank operator in Dyalog APL
我在这个问题 how to build own Each operator using Rank ⍤
.
中看到了答案
Monadic 每个 f¨x
可以表示为 {⊂f⊃⍵}⍤0⊢x
二元每个 x f¨y
可以表示为 x{⊂(⊃⍺)f(⊃⍵)}⍤0⊢y
就此请回答以下问题:
- 为什么每个
¨
运算符都可以表示为
Each←{⍺←⊢ ⋄ ⍺ ⍺⍺{×⎕NC'⍺':⊂(⊃⍺)⍺⍺(⊃⍵) ⋄ ⊂⍺⍺⊃⍵}⍤0⊢⍵}
- 上面的表达式
⍺⍺
是什么意思
提前感谢您的回答。
这个定义基本上结合了上面列出的一元和二元情况。如果 ⍺
存在,×⎕NC'⍺'
将 return 1
,否则 0
,所以它会检查你是否使用 Each
monadically 或 dyadically。
⍺⍺
是 dop Each
的左操作数。即x f Each y
或f Each y
中的f
这里是同一个组合运算符的更详细形式,带有注释:
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 ⍺⍺
}
我在这个问题 ⍤
.
Monadic 每个 f¨x
可以表示为 {⊂f⊃⍵}⍤0⊢x
二元每个 x f¨y
可以表示为 x{⊂(⊃⍺)f(⊃⍵)}⍤0⊢y
就此请回答以下问题:
- 为什么每个
¨
运算符都可以表示为
Each←{⍺←⊢ ⋄ ⍺ ⍺⍺{×⎕NC'⍺':⊂(⊃⍺)⍺⍺(⊃⍵) ⋄ ⊂⍺⍺⊃⍵}⍤0⊢⍵}
- 上面的表达式
⍺⍺
是什么意思
提前感谢您的回答。
这个定义基本上结合了上面列出的一元和二元情况。如果
⍺
存在,×⎕NC'⍺'
将 return1
,否则0
,所以它会检查你是否使用Each
monadically 或 dyadically。⍺⍺
是 dopEach
的左操作数。即x f Each y
或f Each y
中的
f
这里是同一个组合运算符的更详细形式,带有注释:
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 ⍺⍺
}