Commute: Difference between revisions

Jump to navigation Jump to search
457 bytes added ,  22:06, 10 September 2022
m
Text replacement - "<source" to "<syntaxhighlight"
No edit summary
m (Text replacement - "<source" to "<syntaxhighlight")
(3 intermediate revisions by 2 users not shown)
Line 4: Line 4:


This decrements from the vector:
This decrements from the vector:
<source lang=apl>
<syntaxhighlight lang=apl>
       1 -⍨ 1 2 3
       1 -⍨ 1 2 3
0 1 2
0 1 2
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}}
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}}
Double:
Double:
<source lang=apl>
<syntaxhighlight lang=apl>
       +⍨1 2 3
       +⍨1 2 3
2 4 6
2 4 6
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}}
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}}


[[Commute]] can be used to emulate a monadic <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):
[[Commute]] can be used to emulate a monadic <syntaxhighlight lang=apl inline>f g h</syntaxhighlight> [[Fork]] when combined with [[Compose]] (note the following code is not workable APL, but a series of evaluations):
<source lang=apl>
<syntaxhighlight lang=apl>
g⍨∘f⍨∘h⍨ x   
g⍨∘f⍨∘h⍨ x   
x g⍨∘f⍨∘h x ⍝ the last ⍨ is being used monadically, i.e. Selfie
x g⍨∘f⍨∘h x ⍝ the last ⍨ is being used monadically, i.e. Selfie
Line 24: Line 24:
(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>
</syntaxhighlight>
 
== History ==
 
The Commute operator was defined in [[Operators and Functions]] in 1978, and taken up by [[NARS]] as a result. [[Dyalog]], influenced by NARS, included the operator early on. While it didn't appear in [[SHARP APL]], it was included in [[J]] as "Reflex/Passive" (<syntaxhighlight lang=j inline>~</syntaxhighlight>).


== External links ==
== External links ==
Line 35: Line 39:


* [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Operators/Commute.htm Dyalog]
* [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Operators/Commute.htm Dyalog]
* [https://mlochbaum.github.io/BQN/doc/swap.html BQN]


{{APL built-ins}}[[Category:Primitive operators]][[Category:Composition operators]]
{{APL built-ins}}[[Category:Primitive operators]][[Category:Composition operators]]

Navigation menu