Monadic function: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Marshall
(Created page with "A '''monadic function''' is a function with a single argument, written to its right. It is one of three possible function valences; the other two are dyadic an...")
 
m (Kinds of functions category)
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
A '''monadic function''' is a [[function]] with a single [[argument]], written to its right. It is one of three possible function [[valences]]; the other two are [[dyadic]] and [[niladic]]. The term '''prefix function''' is used outside of APL to describe APL's monadic function syntax.
:''For [[operator]]s with one operand, see [[Monadic operator]].''
 
A '''monadic function''' is a [[function]] with a single [[argument]], written to its right. It is one of three possible function [[valence]]s; the other two are [[dyadic]] and [[niladic]]. The term '''prefix function''' is used outside of APL to describe APL's monadic function syntax.


In APL, a single function can be both monadic and dyadic; such a function is called [[ambivalent]] or sometimes variadic. Function pages on the APL Wiki usually only describe one valence of an ambivalent function because the connection between the two may not be consistent across languages. In this case the function is described as monadic even though it may only be half of an ambivalent function.
In APL, a single function can be both monadic and dyadic; such a function is called [[ambivalent]] or sometimes variadic. Function pages on the APL Wiki usually only describe one valence of an ambivalent function because the connection between the two may not be consistent across languages. In this case the function is described as monadic even though it may only be half of an ambivalent function.
Line 9: Line 11:
1 4 9 16 25 25 16 9 4 1
1 4 9 16 25 25 16 9 4 1
</source>
</source>
The functions <source lang=apl inline>f</source>, <source lang=apl inline>×⍨</source> ([[Times]] [[Commute]]), and <source lang=apl inline>⍳</source> ([[Iota]]) are each monadic functions: a named [[dfn]], a [[derived function]], and a [[primitive]], respectively. Evaluating them first produces the [[Index|indices]] up to 5, then multiplies each index by itself to square it, then [[Catenate|catenates]] the resulting list to its [[reverse]].
The functions <source lang=apl inline>f</source>, <source lang=apl inline>×⍨</source> ([[Times]] [[Commute]]), and <source lang=apl inline>⍳</source> ([[Iota]]) are each monadic functions: a named [[dfn]], a [[derived function]], and a [[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 ==
 
* [http://wiki.nars2000.org/index.php/Monadic NARS2000]
{{APL syntax}}[[Category:Kinds of functions]]

Revision as of 14:42, 30 April 2020

For operators with one operand, see Monadic operator.

A monadic function is a function with a single argument, written to its right. It is one of three possible function valences; the other two are dyadic and niladic. The term prefix function is used outside of APL to describe APL's monadic function syntax.

In APL, a single function can be both monadic and dyadic; such a function is called ambivalent or sometimes variadic. Function pages on the APL Wiki usually only describe one valence of an ambivalent function because the connection between the two may not be consistent across languages. In this case the function is described as monadic even though it may only be half of an ambivalent function.

A sequence of monadic functions is evaluated from right to left, a convention drawn from mathematics. Such a sequence can be seen in the following expression:

      f ← {⍵,⌽⍵}
      f ×⍨ ⍳ 5
1 4 9 16 25 25 16 9 4 1

The functions f, ×⍨ (Times Commute), and (Iota) are each monadic functions: a named dfn, a derived function, and a primitive, respectively. Evaluating them first produces the indices up to 5, then multiplies each index by itself to square it, then catenates the resulting list to its reverse.

External links

APL syntax [edit]
General Comparison with traditional mathematicsPrecedenceTacit programming (Train, Hook, Split composition)
Array Numeric literalStringStrand notationObject literalArray notation (design considerations)
Function ArgumentFunction valenceDerived functionDerived operatorNiladic functionMonadic functionDyadic functionAmbivalent functionDefined function (traditional)DfnFunction train
Operator OperandOperator valenceTradopDopDerived operator
Assignment MultipleIndexedSelectiveModified
Other Function axisBracket indexingBranchStatement separatorQuad nameSystem commandUser commandKeywordDot notationFunction-operator overloadingControl structureComment