Defined function (traditional): Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Marshall moved page Tradfn to Defined function over redirect: See talk page)
No edit summary
Line 1: Line 1:
'''Tradfn''' ('''traditional function''' pronounced "trad fun") is a term in use since the introduction of [[dfn]]s. It denotes the traditional way of writing user defined functions, since the very first implementations. The [[canonical representation]] form is equivalent to what the user would type into the [[line editor]] to define the function. An alternative representation consists of the entire [[session]] log transcript after having such a definition has been made. A tradfn operator can also be called a '''tradop''' (pronounced "trad op").
A '''defined function''' (or '''tradfn''', for "traditional function", in [[Dyalog APL]]) is a function defined using a header that includes the function's name. Introduced in [[APL\360]], function definition was universally supported by APL dialects for much of the language's history, and is still commonly used in mainstream APLs. Since the 1990s other ways to [[Function styles|describe functions]] have appeared, with [[J]] and [[K]] rejecting function definition in favor of [[anonymous function]] description. Beginning in the 2010s [[Dyalog]]-based APL dialects including [[ngn/apl]], [[dzaima/APL]], and [[APL\iv]] have removed function definition in favor of [[dfn]]s.


Tradfns used to be the only functional form, and was universally supported. However, a few newer dialects, for example  [[ngn/apl]] and [[dzaima/APL]], do not support tradfns.
In many dialects the function header syntax of defined functions is adapted to allow '''defined operators''' as well.


Tradfns allow both functional and procedural programming, and are essential when for [[object-oriented programming]]. They support a full set of [[keyword]]s for flow control and object declarations.
== Examples ==
 
== Representations ==
The canonical representation form is equivalent to what the user would type into the [[line editor]] to define the function. An alternative representation consists of the entire [[session]] log transcript after having such a definition has been made. A tradfn operator can also be called a '''tradop''' (pronounced "trad op").
 
== Properties ==
Tradfns allow both functional and procedural programming, and are essential for [[object-oriented programming]]. They support a full set of [[keyword]]s for flow control and object declarations.


One of the most noticeable differences from dfns is that tradfns must declare their locals, because assignments are global by default. The declaration is done in a header line which also determines the function's name and calling syntax. Tradfns cannot be nested (although a tradfn can dynamically create other tradfns by [[Fix|"fixing"]] their source, and if the function thus created has a name which has been localised, it will only exist that scope) but ''can'' contain dfns. However, nested functions are less necessary due to tradfns using [[wikipedia:dynamic scoping|dynamic scoping]] as opposed to the lexical scoping of dfns. In other words, a tradfn can "see" locals of its caller.
One of the most noticeable differences from dfns is that tradfns must declare their locals, because assignments are global by default. The declaration is done in a header line which also determines the function's name and calling syntax. Tradfns cannot be nested (although a tradfn can dynamically create other tradfns by [[Fix|"fixing"]] their source, and if the function thus created has a name which has been localised, it will only exist that scope) but ''can'' contain dfns. However, nested functions are less necessary due to tradfns using [[wikipedia:dynamic scoping|dynamic scoping]] as opposed to the lexical scoping of dfns. In other words, a tradfn can "see" locals of its caller.
Line 9: Line 15:
A tradfn can be [[niladic function|niladic]] which causes it to behave syntactically like an array. However, every time its name is referenced, it will run to create a result (if any). Such methods are often used to return a cache or as an entry point for the user.
A tradfn can be [[niladic function|niladic]] which causes it to behave syntactically like an array. However, every time its name is referenced, it will run to create a result (if any). Such methods are often used to return a cache or as an entry point for the user.


== Comparison to dfns ==
Wikipedia has a comparison of [[Wikipedia:Direct_function#Dfns_versus_tradfns|dfns versus tradfns]].
Wikipedia has a comparison of [[Wikipedia:Direct_function#Dfns_versus_tradfns|dfns versus tradfns]].
==External links==
==External links==
===Tutorials===
===Tutorials===

Revision as of 10:27, 13 May 2020

A defined function (or tradfn, for "traditional function", in Dyalog APL) is a function defined using a header that includes the function's name. Introduced in APL\360, function definition was universally supported by APL dialects for much of the language's history, and is still commonly used in mainstream APLs. Since the 1990s other ways to describe functions have appeared, with J and K rejecting function definition in favor of anonymous function description. Beginning in the 2010s Dyalog-based APL dialects including ngn/apl, dzaima/APL, and APL\iv have removed function definition in favor of dfns.

In many dialects the function header syntax of defined functions is adapted to allow defined operators as well.

Examples

Representations

The canonical representation form is equivalent to what the user would type into the line editor to define the function. An alternative representation consists of the entire session log transcript after having such a definition has been made. A tradfn operator can also be called a tradop (pronounced "trad op").

Properties

Tradfns allow both functional and procedural programming, and are essential for object-oriented programming. They support a full set of keywords for flow control and object declarations.

One of the most noticeable differences from dfns is that tradfns must declare their locals, because assignments are global by default. The declaration is done in a header line which also determines the function's name and calling syntax. Tradfns cannot be nested (although a tradfn can dynamically create other tradfns by "fixing" their source, and if the function thus created has a name which has been localised, it will only exist that scope) but can contain dfns. However, nested functions are less necessary due to tradfns using dynamic scoping as opposed to the lexical scoping of dfns. In other words, a tradfn can "see" locals of its caller.

A tradfn can be niladic which causes it to behave syntactically like an array. However, every time its name is referenced, it will run to create a result (if any). Such methods are often used to return a cache or as an entry point for the user.

Comparison to dfns

Wikipedia has a comparison of dfns versus tradfns.

External links

Tutorials

Documentation

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