Reverse Compose: Difference between revisions

Jump to navigation Jump to search
153 bytes added ,  21:10, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "<source" to "<syntaxhighlight")
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 1: Line 1:
{{Built-in|Reverse Compose|⍛}} is a [[primitive operator]] closely related to [[Beside]] (<syntaxhighlight lang=apl inline>∘</source>), which appears in [[Extended Dyalog APL]] and [[dzaima/APL]]. Called [[dyad|dyadically]] with function operands <syntaxhighlight lang=apl inline>f</source> and <syntaxhighlight lang=apl inline>g</source>, it uses <syntaxhighlight lang=apl inline>f</source> [[monad|monadically]] to pre-processes the left argument before applying <syntaxhighlight lang=apl inline>g</source> between the pre-processed left argument and the given right argument. <syntaxhighlight lang=apl inline>X f⍛g Y</source> is thus equivalent to <syntaxhighlight lang=apl inline>(f X) g Y</source>. The operator can be defined as the [[dop]] <syntaxhighlight lang=apl inline>{(⍺⍺ ⍺) ⍵⍵ ⍵}</source>. This dyadic definition matches the [[hook]] function Before, represented as <code>⊸</code> in [[BQN]].
{{Built-in|Reverse Compose|⍛}} is a [[primitive operator]] closely related to [[Beside]] (<syntaxhighlight lang=apl inline>∘</syntaxhighlight>), which appears in [[Extended Dyalog APL]] and [[dzaima/APL]]. 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</source> evaluated to <syntaxhighlight lang=apl inline>g Y</source>, but [[Adám Brudzewsky|Brudzewsky]]'s later Dyalog APL Vision defines<ref>[https://github.com/abrudz/dyalog_vision/blob/main/JotUnderbar.aplo JotUnderbar.aplo]</ref> it to be <syntaxhighlight lang=apl inline>Y f g Y</source>, matching Before. This later definition might also be written <syntaxhighlight lang=apl inline>f⍛g</source>{{←→}}<syntaxhighlight lang=apl inline>f⍛g⍨⍨</source>{{←→}}<syntaxhighlight lang=apl inline>g⍨∘f⍨</source>. In [[dzaima/APL]] the monadic case is simply an error.
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 [[Adám Brudzewsky|Brudzewsky]]'s later Dyalog APL Vision defines<ref>[https://github.com/abrudz/dyalog_vision/blob/main/JotUnderbar.aplo JotUnderbar.aplo]</ref> it to be <syntaxhighlight lang=apl inline>Y f 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 (<syntaxhighlight lang=apl inline>⍨</source>). For example, the square of the left argument minus the right argument can be expressed as:
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!]<syntaxhighlight lang=apl>
[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn//1Hf1EdtE4wPT3/Uu@JR72xdo///AQ Try it online!]<syntaxhighlight lang=apl>
       3×⍨⍛-2
       3×⍨⍛-2
7
7
</source>{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]]}}
</syntaxhighlight>{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]]}}


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:
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:
Line 15: Line 15:
       3 ¯1 4×⍛×∘|¯2 ¯7 1
       3 ¯1 4×⍛×∘|¯2 ¯7 1
2 ¯7 1
2 ¯7 1
</source>{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]]}}
</syntaxhighlight>{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]]}}
== References ==
== References ==
<references/>
<references/>
{{APL built-ins}}[[Category:Primitive operators]][[Category:Composition operators]]
{{APL built-ins}}[[Category:Primitive operators]][[Category:Composition operators]]

Navigation menu