Direct definition (notation)

Ken Iverson's direct definition is a function style written with a name followed by  and a result, using   and   for arguments. The result may be one expression, which is evaluated to apply the function, or three expressions separated by, in which case the middle expression is evaluated to determine which of the other two should be run. Direct definition was used by Iverson and others in publications describing APL in the 1970s and 80s, and was also implemented as a library for SHARP APL that translated a direct definition to a defined function. The argument naming and use of  for a condition later appeared in Dyalog APL's dfns.

The simpler form of direct definition consists of a name and result expression. In the result,  indicates the left argument, and   indicates the right argument. Unlike the later dfns, the name is part of the function definition; direct definition can't define anonymous functions. For example, the following expression would define the function  to add its arguments: In a form with three expressions (four parts total), the middle part is a condition, and is evaluated first. The function's result is then found by evaluating the first expression, if the condition resulted in 0, and the last expression otherwise. The valence of the function is determined by which argument names appear: it's niladic if neither  nor   is used in any expression, monadic if only   is used, and dyadic if   is used. As direct definition was intended to represent pure functions (without side effects), assignment within an expression always localizes its target.

Direct definition was defined in Iverson's 1974 text Elementary Functions, where it was called "formal function definition", and used in writings by Iverson and others including Gene McDonnell and Donald McIntyre. Having been used in the SHARP APL Technical Notes (SATNs) 34 and 35, it was described by Iverson in SATN-36 and subsequently used in SATNs 40 and 41. The syntax was never implemented in SHARP APL itself, but a set of library functions for working with it were defined, including  ("canonical from direct") to translate it to SHARP's function definition, or the "canonical form".