Reverse Compose: Difference between revisions
No edit summary 
(Rewrite and simplify discussion of monadic case) 

Line 1:  Line 1:  
{{BuiltinReverse Compose⍛}}  {{BuiltinReverse Compose⍛}} is a [[primitive operator]] closely related to [[Beside]] (<source lang=apl inline>∘</source>), which appears in [[Extended Dyalog APL]] and [[dzaima/APL]]. Called [[dyaddyadically]] with function operands <source lang=apl inline>f</source> and <source lang=apl inline>g</source>, it uses <source lang=apl inline>f</source> [[monadmonadically]] to preprocesses the left argument before applying <source lang=apl inline>g</source> between the preprocessed left argument and the given right argument. <source lang=apl inline>X f⍛g Y</source> is thus equivalent to <source lang=apl inline>(f X) g Y</source>. The operator can be defined as the [[dop]] <source lang=apl inline>{(⍺⍺ ⍺) ⍵⍵ ⍵}</source>. 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]], <source lang=apl inline>f⍛g Y</source> evaluated to <source lang=apl inline>g Y</source>, but [[Adám BrudzewskyBrudzewsky]]'s later Dyalog APL Vision defines<ref>[https://github.com/abrudz/dyalog_vision/blob/main/JotUnderbar.aplo JotUnderbar.aplo]</ref> it to be <source lang=apl inline>Y f g Y</source>, matching Before. This later definition might also be written <source lang=apl inline>f⍛g</source>{{←→}}<source lang=apl inline>f⍛g⍨⍨</source>{{←→}}<source lang=apl inline>g⍨∘f⍨</source>. In [[dzaima/APL]] the monadic case is simply an error.  
== Common usage ==  == Common usage == 
Revision as of 13:44, 27 May 2022
⍛

Reverse Compose (⍛
) is a primitive operator closely related to Beside (∘
), which appears in Extended Dyalog APL and dzaima/APL. Called dyadically with function operands f
and g
, it uses f
monadically to preprocesses the left argument before applying g
between the preprocessed 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 Brudzewsky's later Dyalog APL Vision defines^{[1]} it to be Y f 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 preprocess 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 splitcompose 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