Commute: Difference between revisions
Jump to navigation
Jump to search
m (Added fork emulation) |
mNo edit summary |
||
Line 16: | Line 16: | ||
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}} | {{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}} | ||
[[Commute]] can be used to emulate a <source lang=apl inline>f g h</source> [[Fork]] when combined with [[Compose]]: | [[Commute]] can be used to emulate a <source lang=apl inline>f g h</source> [[Fork]] when combined with [[Compose]] (note the following code is not workable APL, but a series of evaluations): | ||
<source lang=apl> | <source lang=apl> | ||
g⍨∘f⍨∘h⍨ x | g⍨∘f⍨∘h⍨ x | ||
Line 23: | Line 23: | ||
(h x) g⍨∘f x ⍝ the last ⍨ is being used dyadically, i.e. Swap | (h x) g⍨∘f x ⍝ the last ⍨ is being used dyadically, i.e. Swap | ||
(h x) g⍨ (f x) | (h x) g⍨ (f x) | ||
(f x) g (h x) the last ⍨ is being used dyadically, i.e. Swap | (f x) g (h x) ⍝ the last ⍨ is being used dyadically, i.e. Swap | ||
</source> | </source> | ||
Revision as of 03:18, 8 September 2021
⍨
|
Commute (⍨
) is a monadic operator that takes a dyadic function as operand and modifies how the argument(s) of its derived functions are used. If the derived function is used monadically, the argument is also used as left argument. This usage is also known as Self or, more informally, Selfie. If the derived function is used dyadically, the arguments are swapped. This usage is also known as Swap. The glyph is also used for Commute.
Examples
This decrements from the vector:
1 -⍨ 1 2 3 0 1 2
Double:
+⍨1 2 3 2 4 6
Commute can be used to emulate a f g h
Fork when combined with Compose (note the following code is not workable APL, but a series of evaluations):
g⍨∘f⍨∘h⍨ x x g⍨∘f⍨∘h x ⍝ the last ⍨ is being used monadically, i.e. Selfie x g⍨∘f⍨ h x (h x) g⍨∘f x ⍝ the last ⍨ is being used dyadically, i.e. Swap (h x) g⍨ (f x) (f x) g (h x) ⍝ the last ⍨ is being used dyadically, i.e. Swap
External links
Lessons
Documentation