Dfn: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
No edit summary
Tags: Mobile edit Mobile web edit
No edit summary
Tags: Mobile edit Mobile web edit
(16 intermediate revisions by 4 users not shown)
Line 1: Line 1:
A '''dfn''' (pronounced "dee fun") is an alternative way to define a [[function]] and [[operator]], invented by [[John Scholes]]. A dfn operator can also be called a '''dop''' (pronounced "dee op").
A '''dfn''' (contraction of '''direct function''' or '''dynamic function''', pronounced "dee fun") is an alternative way to define a [[function]] and [[operator]], invented by [[John Scholes]]. A dfn operator can also be called a '''dop''' (pronounced "dee op").


As of 2020, dfns are fully implemented in [[Dyalog APL]], [[NARS2000]], [[ngn/apl]], [[dzaima/APL]], and partially in [[GNU APL]].
John Scholes was responsible for numerous presentations and publications on and about dfns, and until his passing he maintained the [[dfns workspace]], a collection of dfns examples.
 
As of 2020, dfns are fully implemented in [[Dyalog APL]], [[NARS2000]], [[ngn/apl]], [[dzaima/APL]], and partially in [[GNU APL]], although not all dialects implement [[wikipedia:lexical scoping|lexical scoping]], in contrast to the dynamic scoping of [[tradfn]]s. In other words, a dfn cannot "see" locals of its caller, but can see locals of its definer.
 
Wikipedia includes a thorough treatment of [[Wikipedia:dfns|dfns]].
 
== Examples ==
<source lang=apl>
      {⍵*0.5} 16        ⍝ square root
4
      3 {⍵*÷⍺} 27      ⍝ ⍺th root
3
      ⍝ Multiline dfn with optional left parameter and conditional result
      root←{
          ⍺←2          ⍝ square root by default
          ⍺=0:0        ⍝ return zero if zeroth root
          ⍵*÷⍺          ⍝ result
      }</source>


Wikipedia has a full treatment of dfns.
== Documentation ==
* [http://help.dyalog.com/latest/#Language/Defined%20Functions%20and%20Operators/DynamicFunctions/Dynamic%20Functions%20and%20Operators.htm Dyalog]
== External links ==
== External links ==
* [[Wikipedia: Direct function]]
* [[wikipedia:Direct function|Direct function]]
* [[Dyalog Ltd.]]'s [[https://dfns.dyalog.com|dfns website]] (created and maintained by John Scholes until his passing)
 
=== Tutorials ===
* APL Cultivation: [https://chat.stackexchange.com/rooms/52405/conversation/lesson-2-diving-into-functions-in-apl Diving Into Functions in APL]
* Mastering Dyalog: [https://www.dyalog.com/uploads/documents/MasteringDyalogAPL.pdf#page=174 page 174]
 
=== Documentation ===
* [https://help.dyalog.com/latest/#Language/Defined%20Functions%20and%20Operators/DynamicFunctions/Dynamic%20Functions%20and%20Operators.htm Dyalog]
* [https://www.gnu.org/software/apl/apl.html#Section-3_002e7 GNU APL]


{{APL syntax}}
{{APL syntax}}[[Category:Kinds of functions]][[Category:Defining functions]]

Revision as of 11:54, 23 August 2020

A dfn (contraction of direct function or dynamic function, pronounced "dee fun") is an alternative way to define a function and operator, invented by John Scholes. A dfn operator can also be called a dop (pronounced "dee op").

John Scholes was responsible for numerous presentations and publications on and about dfns, and until his passing he maintained the dfns workspace, a collection of dfns examples.

As of 2020, dfns are fully implemented in Dyalog APL, NARS2000, ngn/apl, dzaima/APL, and partially in GNU APL, although not all dialects implement lexical scoping, in contrast to the dynamic scoping of tradfns. In other words, a dfn cannot "see" locals of its caller, but can see locals of its definer.

Wikipedia includes a thorough treatment of dfns.

Examples

      {⍵*0.5} 16        ⍝ square root
4
      3 {⍵*÷⍺} 27       ⍝ ⍺th root
3
      ⍝ Multiline dfn with optional left parameter and conditional result
      root←{
          ⍺←2           ⍝ square root by default
          ⍺=0:0         ⍝ return zero if zeroth root
          ⍵*÷⍺          ⍝ result
      }

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