Derived function: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Categories)
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 5: Line 5:
       3 ⌈/ 2 9 0 ¯1 0 2 5
       3 ⌈/ 2 9 0 ¯1 0 2 5
9 9 0 2 5
9 9 0 2 5
</source>
</syntaxhighlight>
In this statement the [[Reduce]] operator (<source lang=apl inline>/</source>) is applied to the [[Minimum]] function (<source lang=apl inline>⌈</source>) resulting in the derived function <source lang=apl inline>⌈/</source>. In most modern APLs this function can be manipulated like any other function, for example to [[assign]] it to a name:
In this statement the [[Reduce]] operator (<source lang=apl inline>/</syntaxhighlight>) is applied to the [[Minimum]] function (<source lang=apl inline>⌈</syntaxhighlight>) resulting in the derived function <source lang=apl inline>⌈/</syntaxhighlight>. In most modern APLs this function can be manipulated like any other function, for example to [[assign]] it to a name:
<source lang=apl>
<source lang=apl>
       f ← ⌈/
       f ← ⌈/
       3 f 2 9 0 ¯1 0 2 5
       3 f 2 9 0 ¯1 0 2 5
9 9 0 2 5
9 9 0 2 5
</source>
</syntaxhighlight>
Here the value of <source lang=apl inline>f</source> is a derived function. Many APLs display a derived function by placing its operands next to the operator, as it is written:
Here the value of <source lang=apl inline>f</syntaxhighlight> is a derived function. Many APLs display a derived function by placing its operands next to the operator, as it is written:
<source lang=apl>
<source lang=apl>
       f
       f
⌈/
⌈/
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}



Revision as of 21:09, 10 September 2022

A derived function is the result of applying an operator to its operands. Since it is a function, it can then be applied to argument arrays, resulting in other arrays.

Consider for example applying a Windowed Reduction to an array: <source lang=apl>

     3 ⌈/ 2 9 0 ¯1 0 2 5

9 9 0 2 5 </syntaxhighlight> In this statement the Reduce operator (<source lang=apl inline>/</syntaxhighlight>) is applied to the Minimum function (<source lang=apl inline>⌈</syntaxhighlight>) resulting in the derived function <source lang=apl inline>⌈/</syntaxhighlight>. In most modern APLs this function can be manipulated like any other function, for example to assign it to a name: <source lang=apl>

     f ← ⌈/
     3 f 2 9 0 ¯1 0 2 5

9 9 0 2 5 </syntaxhighlight> Here the value of <source lang=apl inline>f</syntaxhighlight> is a derived function. Many APLs display a derived function by placing its operands next to the operator, as it is written: <source lang=apl>

     f

⌈/ </syntaxhighlight>

Works in: Dyalog APL

In APL a user-defined operator such as a tradop or dop creates a derived function from its arguments without executing any of the user's code. In J, the user's code is evaluated and must return a value, which could but doesn't have to be a derived function.


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