Reverse Compose: Difference between revisions
m (Adám Brudzewsky moved page Reverse Compose (operator) to Reverse Compose) |
(aka "behind") |
||
(23 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Built-in|Reverse Compose|⍛}}, | {{Built-in|Reverse Compose|⍛}}, '''Before''' or '''Behind''' is a [[primitive operator]] closely related to [[Beside]] (<syntaxhighlight lang=apl inline>∘</syntaxhighlight>), which appears in [[Extended Dyalog APL]], [[dzaima/APL]], [[April]] and [[Kap]]. Called [[dyad|dyadically]] with function operands <syntaxhighlight lang=apl inline>f</syntaxhighlight> and <syntaxhighlight lang=apl inline>g</syntaxhighlight>, it uses <syntaxhighlight lang=apl inline>f</syntaxhighlight> [[monad|monadically]] to pre-processes the left argument before applying <syntaxhighlight lang=apl inline>g</syntaxhighlight> between the pre-processed left argument and the given right argument. <syntaxhighlight lang=apl inline>X f⍛g Y</syntaxhighlight> is thus equivalent to <syntaxhighlight lang=apl inline>(f X) g Y</syntaxhighlight>. The operator can be defined as the [[dop]] <syntaxhighlight lang=apl inline>{(⍺⍺ ⍺) ⍵⍵ ⍵}</syntaxhighlight>. This dyadic definition matches the [[hook]] function Before, represented as <code>⊸</code> in [[BQN]]. | ||
Unlike Before, the [[monad]]ic case of Reverse Compose has differed across implementations. When introduced by [[Extended Dyalog APL]], <syntaxhighlight lang=apl inline>f⍛g Y</syntaxhighlight> evaluated to <syntaxhighlight lang=apl inline>g Y</syntaxhighlight>, but the later [[Dyalog APL Vision]], as well as [[April]] and [[Kap]], define it to be <syntaxhighlight lang=apl inline>(f Y) g Y</syntaxhighlight>, matching Before. This later definition might also be written <syntaxhighlight lang=apl inline>f⍛g</syntaxhighlight>{{←→}}<syntaxhighlight lang=apl inline>f⍛g⍨⍨</syntaxhighlight>{{←→}}<syntaxhighlight lang=apl inline>g⍨∘f⍨</syntaxhighlight>. In [[dzaima/APL]] the monadic case is simply an error. | |||
== Common usage == | == Common usage == | ||
Its plain usage is to pre-process left arguments without needing one or more applications of Commute (< | Its plain usage is to pre-process left arguments without needing one or more applications of Commute (<syntaxhighlight lang=apl inline>⍨</syntaxhighlight>). For example, the square of the left argument minus the right argument can be expressed as: | ||
[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn//1Hf1EdtE4wPT3/Uu@JR72xdo///AQ Try it online!]< | [https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn//1Hf1EdtE4wPT3/Uu@JR72xdo///AQ Try it online!]<syntaxhighlight lang=apl> | ||
3×⍨⍛-2 | 3×⍨⍛-2 | ||
7 | 7 | ||
</ | </syntaxhighlight>{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]], [[Kap]]}} | ||
It can also be combined with | It can also be combined with Beside to create the [[split-compose]] construct. Here, we take the [[sign]] of the left argument and apply it to (that is, multiply it with) the absolute value of the right argument: | ||
[https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtE4wVDq03VDA5PP1R72wg0TGj5tB6I6CYuYLh//8A Try it online!]< | [https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtE4wVDq03VDA5PP1R72wg0TGj5tB6I6CYuYLh//8A Try it online!]<syntaxhighlight lang=apl> | ||
3 ¯1 4×⍛×∘|¯2 ¯7 1 | 3 ¯1 4×⍛×∘|¯2 ¯7 1 | ||
2 ¯7 1 | 2 ¯7 1 | ||
</ | </syntaxhighlight>{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]], [[Kap]]}} | ||
{{APL built-ins}} | == External links == | ||
=== Documentation === | |||
* [https://kapdemo.dhsdevelopments.com/reference.html#_inverse_compose Kap] | |||
* [https://mlochbaum.github.io/BQN/doc/hook.html BQN] (as <code>⊸</code>) | |||
=== Publications === | |||
* [https://github.com/abrudz/primitives/blob/main/behind.aplf APL model] | |||
{{APL built-ins}}[[Category:Primitive operators]][[Category:Composition operators]] |
Latest revision as of 13:57, 28 June 2024
⍛
|
Reverse Compose (⍛
), Before or Behind is a primitive operator closely related to Beside (∘
), which appears in Extended Dyalog APL, dzaima/APL, April and Kap. Called dyadically with function operands f
and g
, it uses f
monadically to pre-processes the left argument before applying g
between the pre-processed left argument and the given right argument. X f⍛g Y
is thus equivalent to (f X) g Y
. The operator can be defined as the dop {(⍺⍺ ⍺) ⍵⍵ ⍵}
. This dyadic definition matches the hook function Before, represented as ⊸
in BQN.
Unlike Before, the monadic case of Reverse Compose has differed across implementations. When introduced by Extended Dyalog APL, f⍛g Y
evaluated to g Y
, but the later Dyalog APL Vision, as well as April and Kap, define it to be (f Y) g Y
, matching Before. This later definition might also be written f⍛g
f⍛g⍨⍨
g⍨∘f⍨
. In dzaima/APL the monadic case is simply an error.
Common usage
Its plain usage is to pre-process left arguments without needing one or more applications of Commute (⍨
). For example, the square of the left argument minus the right argument can be expressed as:
3×⍨⍛-2 7
It can also be combined with Beside to create the split-compose construct. Here, we take the sign of the left argument and apply it to (that is, multiply it with) the absolute value of the right argument:
3 ¯1 4×⍛×∘|¯2 ¯7 1 2 ¯7 1