Function styles: Difference between revisions

Jump to navigation Jump to search
45 bytes added ,  22:28, 10 September 2022
m
Text replacement - "<source" to "<syntaxhighlight"
m (Text replacement - "</source>" to "</syntaxhighlight>")
m (Text replacement - "<source" to "<syntaxhighlight")
Line 13: Line 13:
{{Main|Direct definition}}
{{Main|Direct definition}}


Although the term "direct definition" has been used in various ways by different authors, one of the more notable uses is that described by [[Ken Iverson]] in ''Elementary Functions'', published 1974.<ref>[[Ken Iverson]]. ''Elementary Functions'' [https://www.jsoftware.com/papers/DirectDef.htm chapter 10]. [[IBM]]. 1974.</ref> Initially called "formal function definition", this style was called "direct definition" by Iverson and others at [[IPSA]] when they used it to describe new language features in [[SHARP APL]].<ref name="satn-direct"/> It was never implemented as part of SHARP APL, although utilities to translate it to SHARP's function definition, or the "canonical form", were provided. Iverson's direct definition required the name of the function like existing defined functions, but not those of the arguments: instead the left argument was named <source lang=apl inline>⍺</syntaxhighlight> and the right argument <source lang=apl inline>⍵</syntaxhighlight>. This argument naming would later by adopted by [[John Scholes]]' [[dfn]]s, but direct definition differed in many other respects.
Although the term "direct definition" has been used in various ways by different authors, one of the more notable uses is that described by [[Ken Iverson]] in ''Elementary Functions'', published 1974.<ref>[[Ken Iverson]]. ''Elementary Functions'' [https://www.jsoftware.com/papers/DirectDef.htm chapter 10]. [[IBM]]. 1974.</ref> Initially called "formal function definition", this style was called "direct definition" by Iverson and others at [[IPSA]] when they used it to describe new language features in [[SHARP APL]].<ref name="satn-direct"/> It was never implemented as part of SHARP APL, although utilities to translate it to SHARP's function definition, or the "canonical form", were provided. Iverson's direct definition required the name of the function like existing defined functions, but not those of the arguments: instead the left argument was named <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> and the right argument <syntaxhighlight lang=apl inline>⍵</syntaxhighlight>. This argument naming would later by adopted by [[John Scholes]]' [[dfn]]s, but direct definition differed in many other respects.


== Anonymous functions ==
== Anonymous functions ==
Line 19: Line 19:


In the 1990s array language designers began experimenting with forms that allowed a function to be created without ever giving it a name, often influenced by [[wikipedia:Lisp (programming language)|Lisp]]'s lambda expressions. Such anonymous forms appeared in several languages, including an early but less influential form in [[NARS]]:
In the 1990s array language designers began experimenting with forms that allowed a function to be created without ever giving it a name, often influenced by [[wikipedia:Lisp (programming language)|Lisp]]'s lambda expressions. Such anonymous forms appeared in several languages, including an early but less influential form in [[NARS]]:
* 1981: [[NARS]] defines its own type of [[direct definition (NARS)|direct definition]] written with two strings joined by the operator <source lang=apl inline>∇</syntaxhighlight>
* 1981: [[NARS]] defines its own type of [[direct definition (NARS)|direct definition]] written with two strings joined by the operator <syntaxhighlight lang=apl inline>∇</syntaxhighlight>
* 1990: [[J]] uses the <source lang=j inline>:</syntaxhighlight> operator for "explicit definition"; in 2020 it adds a more [[dfn]]-like "direct definition"<ref>Jsoftware. [https://code.jsoftware.com/wiki/Vocabulary/DirectDefinition Direct Definition]. Accessed 2020-10-24.</ref> syntax with doubled curly braces
* 1990: [[J]] uses the <syntaxhighlight lang=j inline>:</syntaxhighlight> operator for "explicit definition"; in 2020 it adds a more [[dfn]]-like "direct definition"<ref>Jsoftware. [https://code.jsoftware.com/wiki/Vocabulary/DirectDefinition Direct Definition]. Accessed 2020-10-24.</ref> syntax with doubled curly braces
* 1994: [[K]]'s functions are written with curly braces
* 1994: [[K]]'s functions are written with curly braces
* 1996: [[Dyalog APL]] adds [[dfn]]s, another kind of functions written with curly braces
* 1996: [[Dyalog APL]] adds [[dfn]]s, another kind of functions written with curly braces
Line 32: Line 32:
{{Main|Tacit programming}}
{{Main|Tacit programming}}


Another kind of function which can be created by the programmer are tacit functions, so named because they do not include any mention of their arguments, leaving them unsaid. Languages with tacit functions call the other types of functions, which do refer to arguments as part of a function body, "explicit" functions. Tacit functions are created as values: [[derived function]]s and [[train]]s are two kinds of tacit function. For example <source lang=apl inline>+/</syntaxhighlight>, [[Plus]] [[Reduce]], is a derived function that can be created in any APL. However, early APLs usually did not allow [[assign]]ing a name to such functions: the only ways to call them were to write the function out explicitly and to define an equivalent explicit function. Function assignment became more common in the 1980s, and after the promotion of tacit programming by [[J]] in the 90s it is present in all new APLs.
Another kind of function which can be created by the programmer are tacit functions, so named because they do not include any mention of their arguments, leaving them unsaid. Languages with tacit functions call the other types of functions, which do refer to arguments as part of a function body, "explicit" functions. Tacit functions are created as values: [[derived function]]s and [[train]]s are two kinds of tacit function. For example <syntaxhighlight lang=apl inline>+/</syntaxhighlight>, [[Plus]] [[Reduce]], is a derived function that can be created in any APL. However, early APLs usually did not allow [[assign]]ing a name to such functions: the only ways to call them were to write the function out explicitly and to define an equivalent explicit function. Function assignment became more common in the 1980s, and after the promotion of tacit programming by [[J]] in the 90s it is present in all new APLs.


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

Navigation menu