Direct definition (operator): Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Marshall moved page Direct definition (NARS) to Direct definition (operator): Also appears in Iverson publications)
(Rework to include Iverson's versions of the operator)
 
Line 1: Line 1:
:''The [[Del]] glyph <code>∇</code> is more commonly used for [[dfn]] recursion or to indicate a [[defined function]].''
:''The [[Del]] glyph <code>∇</code> is more commonly used for [[dfn]] recursion or to indicate a [[defined function]].''


{{Built-in|Direct definition|∇}}, in [[NARS]], is a [[primitive]] [[dyadic operator]] that defines an [[anonymous function]] based on source [[string]]s. Its left operand is the source for the function's [[dyadic]] case and the right is the source for the [[monadic]] case. One of these operands may be replaced with a [[Jot]] (using this operator as an operand as with [[Outer Product]]) to indicate an undefined case and create a strictly monadic or dyadic function.
{{Built-in|Direct definition|∇}}, or '''function definition''', is a [[primitive]] [[dyadic operator]] that defines an [[anonymous function]] based on source [[string]]s. Its left operand is the source for the function's [[dyadic]] case and the right is the source for the [[monadic]] case. It appears in [[NARS]] and several publications by [[Ken Iverson]]: an [[APL81]] paper with Peter Wooster,<ref>[[Ken Iverson]] and Peter Wooster. [https://dl.acm.org/doi/abs/10.1145/390007.805349 A function definition operator] at [[APL81]].</ref> [[Rationalized APL]], and [[A Dictionary of APL]]. Definitions vary, but in all cases, the format of a source string is similar to that used in the informal [[Direct definition (notation)|direct definition notation]], with <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> and <syntaxhighlight lang=apl inline>⍵</syntaxhighlight> for the left and right [[argument]]s. Another token, <syntaxhighlight lang=apl inline>_</syntaxhighlight> in NARS and <syntaxhighlight lang=apl inline>∆</syntaxhighlight> in Iverson's papers, is added to indicate [[recursion]]. Multiple expressions can be used by separating with <syntaxhighlight lang=apl inline>⋄</syntaxhighlight>. Various forms of control flow have been defined.


The format of a source string is similar to that used in [[Direct definition (notation)|Iverson's direct definition]], with several small differences. Multiple expressions can be used if separated by <syntaxhighlight lang=apl inline>⋄</syntaxhighlight>. <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> and <syntaxhighlight lang=apl inline>⍵</syntaxhighlight> indicate the left and right [[argument]]s, and <syntaxhighlight lang=apl inline>_</syntaxhighlight> is added to indicate [[recursion]]. Conditions are still indicated with colons <syntaxhighlight lang=apl inline>:</syntaxhighlight>, but the mechanism is extended: rather than a boolean condition placed between false and true cases, it's placed first, and returns a scalar or vector of natural numbers. Each number indicates one of the following groups of statements (separated by further <syntaxhighlight lang=apl inline>:</syntaxhighlight>s and numbered starting at 0), and these groups will then be evaluated, with the result of the last evaluated expression returned from the function as a whole.
In [[NARS]], operands are single strings, and one of them may be replaced with a [[Jot]] (using this operator as an operand as with [[Outer Product]]) to indicate an undefined case and create a strictly monadic or dyadic function. Conditions are indicated with colons <syntaxhighlight lang=apl inline>:</syntaxhighlight> as in direct definition notation, but the mechanism is extended: rather than a boolean condition placed between false and true cases, it's placed first, and returns a scalar or vector of natural numbers. Each number indicates one of the following groups of statements (separated by further <syntaxhighlight lang=apl inline>:</syntaxhighlight>s and numbered starting at 0), and these groups will then be evaluated, with the result of the last evaluated expression returned from the function as a whole.


== External links ==
== Documentation ==
* [https://www.sudleyplace.com/APL/Nested%20Arrays%20System.pdf#page=58 Documentation]
* [https://www.sudleyplace.com/APL/Nested%20Arrays%20System.pdf#page=58 NARS]


== References ==
<references/>
{{APL built-ins}}[[Category:Primitive operators]][[Category:Defining functions]]
{{APL built-ins}}[[Category:Primitive operators]][[Category:Defining functions]]

Latest revision as of 02:32, 8 March 2024

The Del glyph is more commonly used for dfn recursion or to indicate a defined function.

Direct definition (), or function definition, is a primitive dyadic operator that defines an anonymous function based on source strings. Its left operand is the source for the function's dyadic case and the right is the source for the monadic case. It appears in NARS and several publications by Ken Iverson: an APL81 paper with Peter Wooster,[1] Rationalized APL, and A Dictionary of APL. Definitions vary, but in all cases, the format of a source string is similar to that used in the informal direct definition notation, with and for the left and right arguments. Another token, _ in NARS and in Iverson's papers, is added to indicate recursion. Multiple expressions can be used by separating with . Various forms of control flow have been defined.

In NARS, operands are single strings, and one of them may be replaced with a Jot (using this operator as an operand as with Outer Product) to indicate an undefined case and create a strictly monadic or dyadic function. Conditions are indicated with colons : as in direct definition notation, but the mechanism is extended: rather than a boolean condition placed between false and true cases, it's placed first, and returns a scalar or vector of natural numbers. Each number indicates one of the following groups of statements (separated by further :s and numbered starting at 0), and these groups will then be evaluated, with the result of the last evaluated expression returned from the function as a whole.

Documentation

References

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector