Monadic operator: Difference between revisions

Jump to navigation Jump to search
514 bytes added ,  12:58, 24 March 2020
Elaborate on overloading
(Connection to function-operator overloading)
(Elaborate on overloading)
Line 3: Line 3:
The term "monadic operator" refers to the [[operator valence|valence]] of the operator itself, that is, the number of operands. When applied, it produces a [[derived function]], which can have a different [[function valence]]. For example, the [[Windowed Reduce|2-wise reduction]] <source lang=apl inline>2 =/ 1 2 2 3</source> illustrates the monadic operator [[Reduce]] (<source lang=apl inline>/</source>) applied to a single operand <source lang=apl inline>=</source>, and then to two arguments <source lang=apl inline>2</source> and <source lang=apl inline>1 2 2 3</source>. We say it is a "monadic operator called dyadically".
The term "monadic operator" refers to the [[operator valence|valence]] of the operator itself, that is, the number of operands. When applied, it produces a [[derived function]], which can have a different [[function valence]]. For example, the [[Windowed Reduce|2-wise reduction]] <source lang=apl inline>2 =/ 1 2 2 3</source> illustrates the monadic operator [[Reduce]] (<source lang=apl inline>/</source>) applied to a single operand <source lang=apl inline>=</source>, and then to two arguments <source lang=apl inline>2</source> and <source lang=apl inline>1 2 2 3</source>. We say it is a "monadic operator called dyadically".


When called monadically, a monadic operator has the same syntax as a [[dyadic function]]: in each case, there is one value to the left and one to the right of the operator or function. The difference is that while the value on the right is always an [[argument]], the one on the left is an [[operand]] to the operator but an argument to the function. In some dialects this ambiguity is used to allow [[function-operator overloading]], where a value can be either a monadic operator or a dyadic function depending on context.
When called monadically, a monadic operator with an array operand has the same syntax as a [[dyadic function]]: in each case, there is one array to the left and one to the right of the operator or function. The difference is that while the value on the right is always an [[argument]], the one on the left is an [[operand]] to the operator but an argument to the function. This means that the operator can be applied in two steps: in most modern dialects the operand and its operator can be separated, for example changing the [[Constant operator]] call <source lang=apl inline>A ⍨ B</source> to <source lang=apl inline>toA←A ⍨ ⋄ toA B</source>, but few allow the array-function combination that would be required to change the equivalent [[Identity]] call <source lang=apl inline>A ⊢ B</source> to <source lang=apl inline>toA←A ⊢ ⋄ toA B</source>. In some dialects this ambiguity is used to allow [[function-operator overloading]], where a value can be either a monadic operator or a dyadic function depending on context.
{{APL syntax}}
{{APL syntax}}

Navigation menu