Defined function (traditional): Difference between revisions
Revision as of 09:57, 13 May 2020
Tradfn (traditional function pronounced "trad fun") is a term in use since the introduction of dfns. 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").
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.
Wikipedia has a comparison of dfns versus tradfns.
- APL Cultivation: tradfns