`{⊂⍵}` 与 `⊂` 有何不同?

How is `{⊂⍵}` different from just `⊂`?

我正在阅读 Hui 和 Kromberg 最近的 "APL Since 1978",在 (stencil) 的讨论中,他们给出了以下示例:

      {⊂⍵}⌺5⊢'abcde'
   abc   abcd  abcde  bcde   cde

为什么 {⊂⍵} 而不是 ?我对 APL 还是很陌生,但我天真地认为通常 {f⍵} 应该等同于 f 单子调用时。

根据经验,我可以看出情况并非如此:

      ⊂⌺5⊢'abcde'
DOMAIN ERROR
      ⊂⌺5⊢'abcde'
      ∧

但是我不明白为什么。

你是绝对正确的 {⊂⍵} 等价于 当单子调用时,但是根据 the documentation:

f is invoked dyadically with a vector left argument indicating for each axis the number of fill elements and on what side; positive values mean that the padding precedes the array values, negative values mean that the padding follows the array values.

我们可以通过使函数 return 包含两个参数来说明这一点:

      {⊂⍺ ⍵}⌺5⊢'abcde'
┌─────────┬─────────┬─────────┬──────────┬──────────┐
│┌─┬─────┐│┌─┬─────┐│┌─┬─────┐│┌──┬─────┐│┌──┬─────┐│
││2│  abc│││1│ abcd│││0│abcde│││¯1│bcde │││¯2│cde  ││
│└─┴─────┘│└─┴─────┘│└─┴─────┘│└──┴─────┘│└──┴─────┘│
└─────────┴─────────┴─────────┴──────────┴──────────┘

此左参数旨在满足 左参数的要求,因此可以轻松删除添加的填充:

      {⊂⍺↓⍵}⌺5⊢'abcde'
┌───┬────┬─────┬────┬───┐
│abc│abcd│abcde│bcde│cde│
└───┴────┴─────┴────┴───┘

如果您想要默认操作数而不是 {⊂⍵},那么您可以使用 ⊢∘⊂(相当于 {⍺⊢⊂⍵},因此相当于 {⊂⍵}),或者在版本 18.0 中, ⊂⍤⊢(相当于 {⊂⍺⊢⍵},因此 {⊂⍵})。