Monadic function: Difference between revisions

Jump to navigation Jump to search
36 bytes added ,  22:26, 10 September 2022
m
Text replacement - "<source" to "<syntaxhighlight"
m (Text replacement - "</source>" to "</syntaxhighlight>")
m (Text replacement - "<source" to "<syntaxhighlight")
 
Line 6: Line 6:


A sequence of monadic functions is evaluated from right to left, a convention [[Comparison with traditional mathematics|drawn from mathematics]]. Such a sequence can be seen in the following expression:
A sequence of monadic functions is evaluated from right to left, a convention [[Comparison with traditional mathematics|drawn from mathematics]]. Such a sequence can be seen in the following expression:
<source lang=apl>
<syntaxhighlight lang=apl>
       f ← {⍵,⌽⍵}
       f ← {⍵,⌽⍵}
       f ×⍨ ⍳ 5
       f ×⍨ ⍳ 5
1 4 9 16 25 25 16 9 4 1
1 4 9 16 25 25 16 9 4 1
</syntaxhighlight>
</syntaxhighlight>
The functions <source lang=apl inline>f</syntaxhighlight>, <source lang=apl inline>×⍨</syntaxhighlight> ([[Times]] [[Commute]]), and <source lang=apl inline>⍳</syntaxhighlight> ([[Iota]]) are each monadic functions: a named [[dfn]], a [[derived function]], and a [[primitive function|primitive]], respectively. Evaluating them first produces the [[Index|indices]] up to 5, then multiplies each index by itself to square it, then [[catenate]]s the resulting list to its [[reverse]].
The functions <syntaxhighlight lang=apl inline>f</syntaxhighlight>, <syntaxhighlight lang=apl inline>×⍨</syntaxhighlight> ([[Times]] [[Commute]]), and <syntaxhighlight lang=apl inline>⍳</syntaxhighlight> ([[Iota]]) are each monadic functions: a named [[dfn]], a [[derived function]], and a [[primitive function|primitive]], respectively. Evaluating them first produces the [[Index|indices]] up to 5, then multiplies each index by itself to square it, then [[catenate]]s the resulting list to its [[reverse]].


== External links ==
== External links ==

Navigation menu