Reverse Compose: Difference between revisions
mNo edit summary |
m (→Common usage) |
||
Line 11: | Line 11: | ||
</source>{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]]}} | </source>{{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 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: | ||
[https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtE4wVDq03VDA5PP1R72wg0TGj5tB6I6CYuYLh//8A Try it online!]<source lang=apl> | [https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtE4wVDq03VDA5PP1R72wg0TGj5tB6I6CYuYLh//8A Try it online!]<source lang=apl> | ||
3 ¯1 4×⍛×∘|¯2 ¯7 1 | 3 ¯1 4×⍛×∘|¯2 ¯7 1 |
Revision as of 06:17, 6 September 2021
⍛
|
Reverse Compose (⍛
), also known as Before, is a primitive operator closely related to Beside (∘
), also known as After. 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 {(⍺⍺ ⍺) ⍵⍵ ⍵}
.
Reverse compose was introduced in Extended Dyalog APL, and then adopted into dzaima/APL. Its dyadic case matches I's Hook (h
), which is a reflected form of a J Hook, while Backhook (H
) matches the ordinary Hook or Compose: because I's precedence order is left to right, it considers the "reversed" APL form to be primary.
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