Direct definition (notation): Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Created page with "Ken Iverson's '''direct definition''' is a function style written with a name followed by <code>:</code> and a result, using <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> and <syntaxhighlight lang=apl inline>⍵</syntaxhighlight> for arguments. The result may be one expression, which is evaluated to apply the function, or three expressions separated by <code>:</code>, in which case the middle expression is evaluated to determine which of the other tw...")
 
m (Marshall moved page Direct definition (Iverson) to Direct definition (notation): Direct definition operator possibly also developed by Iverson)
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
The [[valence]] of the function is determined by which argument names appear: it's [[niladic]] if neither <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> nor <syntaxhighlight lang=apl inline>⍵</syntaxhighlight> is used in any expression, [[monadic]] if only <syntaxhighlight lang=apl inline>⍵</syntaxhighlight> is used, and [[dyadic]] if <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> is used. As direct definition was intended to represent pure functions (without side effects), [[assignment]] within an expression always localizes its target.
The [[valence]] of the function is determined by which argument names appear: it's [[niladic]] if neither <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> nor <syntaxhighlight lang=apl inline>⍵</syntaxhighlight> is used in any expression, [[monadic]] if only <syntaxhighlight lang=apl inline>⍵</syntaxhighlight> is used, and [[dyadic]] if <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> is used. As direct definition was intended to represent pure functions (without side effects), [[assignment]] within an expression always localizes its target.


Direct definition was defined in Iverson's 1974 text ''Elementary Functions'',<ref>[[Ken Iverson]]. ''Elementary Functions'' [https://www.jsoftware.com/papers/DirectDef.htm chapter 10]. [[IBM]]. 1974.</ref> where it was called "formal function definition", and used in writings by Iverson<ref>[[K. E. Iverson]]. [https://www.jsoftware.com/papers/APLStyle.htm Programming Style in APL] at [[IPSA '78]].</ref> and others including [[Gene McDonnell]]<ref>[[Eugene McDonnell]] and Jeffrey Shallit. [https://www.jsoftware.com/papers/eem/infinity.htm Extending APL to infinity] at [[APL80]].</ref><ref>[[Eugene McDonnell]]. SATN-40: [https://www.jsoftware.com/papers/satn40.htm Complex Numbers]. 1981-06-20.</ref> and [[Donald McIntyre]].<ref>[[D. B. McIntyre]]. "Experience with Direct Definition One-liners in Writing APL Applications" at [[IPSA '78]].</ref> Having been used in the [[SHARP APL]] Technical Notes (SATNs) 34 and 35, it was described by Iverson in SATN-36 and subsequently used in SATNs 40 and 41. The syntax was never implemented in [[SHARP APL]] itself, but a set of library functions for working with it were defined, including <syntaxhighlight lang=apl inline>CFD</syntaxhighlight> ("canonical from direct") to translate it to SHARP's function definition, or the "canonical form".<ref>[[Ken Iverson]]. SATN-36: Direct Definition. 1980-04-20.</ref>
Direct definition was defined in Iverson's 1974 text ''Elementary Functions'',<ref>[[Ken Iverson]]. ''Elementary Functions'' [https://www.jsoftware.com/papers/DirectDef.htm chapter 10]. [[IBM]]. 1974.</ref> where it was called "formal function definition", and used in writings by Iverson<ref>[[Ken Iverson|K. E. Iverson]]. [https://www.jsoftware.com/papers/APLStyle.htm Programming Style in APL] at [[IPSA '78]].</ref> and others including [[Gene McDonnell]]<ref>[[Eugene McDonnell]] and Jeffrey Shallit. [https://www.jsoftware.com/papers/eem/infinity.htm Extending APL to infinity] at [[APL80]].</ref><ref>[[Eugene McDonnell]]. SATN-40: [https://www.jsoftware.com/papers/satn40.htm Complex Numbers]. 1981-06-20.</ref> and [[Donald McIntyre]].<ref>[[Donald McIntyre|D. B. McIntyre]]. "Experience with Direct Definition One-liners in Writing APL Applications" at [[IPSA '78]].</ref> Having been used in the [[SHARP APL]] Technical Notes (SATNs) 34 and 35, it was described by Iverson in SATN-36 and subsequently used in SATNs 40 and 41. The syntax was never implemented in [[SHARP APL]] itself, but a set of library functions for working with it were defined, including <syntaxhighlight lang=apl inline>CFD</syntaxhighlight> ("canonical from direct") to translate it to SHARP's function definition, or the "canonical form".<ref>[[Ken Iverson]]. SATN-36: Direct Definition. 1980-04-20.</ref>


== References ==
== References ==
<references/>
<references/>
{{APL syntax}}[[Category:Kinds of functions]][[Category:Defining functions]]
{{APL syntax}}[[Category:Kinds of functions]][[Category:Defining functions]]

Latest revision as of 01:58, 8 March 2024

Ken Iverson's direct definition is a function style written with a name followed by : and a result, using and for arguments. The result may be one expression, which is evaluated to apply the function, or three expressions separated by :, in which case the middle expression is evaluated to determine which of the other two should be run. Direct definition was used by Iverson and others in publications describing APL in the 1970s and 80s, and was also implemented as a library for SHARP APL that translated a direct definition to a defined function. The argument naming and use of : for a condition later appeared in Dyalog APL's dfns.

The simpler form of direct definition consists of a name and result expression. In the result, indicates the left argument, and indicates the right argument. Unlike the later dfns, the name is part of the function definition; direct definition can't define anonymous functions. For example, the following expression would define the function plus to add its arguments:

plus:⍺+⍵

In a form with three expressions (four parts total), the middle part is a condition, and is evaluated first. The function's result is then found by evaluating the first expression, if the condition resulted in 0, and the last expression otherwise.

fac:⍵×fac ⍵-1:⍵=1:1

The valence of the function is determined by which argument names appear: it's niladic if neither nor is used in any expression, monadic if only is used, and dyadic if is used. As direct definition was intended to represent pure functions (without side effects), assignment within an expression always localizes its target.

Direct definition was defined in Iverson's 1974 text Elementary Functions,[1] where it was called "formal function definition", and used in writings by Iverson[2] and others including Gene McDonnell[3][4] and Donald McIntyre.[5] Having been used in the SHARP APL Technical Notes (SATNs) 34 and 35, it was described by Iverson in SATN-36 and subsequently used in SATNs 40 and 41. The syntax was never implemented in SHARP APL itself, but a set of library functions for working with it were defined, including CFD ("canonical from direct") to translate it to SHARP's function definition, or the "canonical form".[6]

References

  1. Ken Iverson. Elementary Functions chapter 10. IBM. 1974.
  2. K. E. Iverson. Programming Style in APL at IPSA '78.
  3. Eugene McDonnell and Jeffrey Shallit. Extending APL to infinity at APL80.
  4. Eugene McDonnell. SATN-40: Complex Numbers. 1981-06-20.
  5. D. B. McIntyre. "Experience with Direct Definition One-liners in Writing APL Applications" at IPSA '78.
  6. Ken Iverson. SATN-36: Direct Definition. 1980-04-20.
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