Direct function

A direct function (dfn, pronounced "dee fun") is an alternative way to define a function and operator (a higher-order function) in the programming language APL. A direct operator can also be called a dop (pronounced "dee op"). They were invented by John Scholes in 1996.[1] They are a unique combination of array programming, higher-order function, and functional programming, and are a major distinguishing advance of early 21st century APL over prior versions.

A dfn is a sequence of possibly guarded expressions (or just a guard) between { and }, separated by or new-lines, wherein denotes the left argument and the right, and denotes recursion (function self-reference). For example, the function PT tests whether each row of is a Pythagorean triplet (by testing whether the sum of squares equals twice the square of the maximum).

   PT {(+/*2)=2×(/)*2}
   PT 3 4 5
1
   x
 4  5  3
 3 11  6
 5 13 12
17 16  8
11 12  4
17 15  8
   PT x
1 0 1 0 0 1

The factorial function as a dfn:

   fact {0=⍵:1  × -1}
   fact 5
120
   fact¨ 10    ⍝ fact applied to each element of 0 to 9
1 1 2 6 24 120 720 5040 40320 362880
  1. ^ Scholes, John (October 1996). "Direct Functions in Dyalog APL" (PDF). Vector. 13 (2). Retrieved 16 September 2019.

© MMXXIII Rich X Search. We shall prevail. All rights reserved. Rich X Search