<s>
A	O
direct	B-Application
function	I-Application
(	O
dfn	O
,	O
pronounced	O
"	O
dee	O
fun	O
"	O
)	O
is	O
an	O
alternative	O
way	O
to	O
define	O
a	O
function	O
and	O
operator	B-Language
(	O
a	O
higher-order	B-Language
function	I-Language
)	O
in	O
the	O
programming	O
language	O
APL	B-Language
.	O
</s>
<s>
A	O
direct	O
operator	B-Language
can	O
also	O
be	O
called	O
a	O
dop	O
(	O
pronounced	O
"	O
dee	O
op	O
"	O
)	O
.	O
</s>
<s>
They	O
were	O
invented	O
by	O
John	B-Application
Scholes	I-Application
in	O
1996	O
.	O
</s>
<s>
They	O
are	O
a	O
unique	O
combination	O
of	O
array	B-Application
programming	I-Application
,	O
higher-order	B-Language
function	I-Language
,	O
and	O
functional	B-Language
programming	I-Language
,	O
and	O
are	O
a	O
major	O
distinguishing	O
advance	O
of	O
early	O
21st	O
century	O
APL	B-Language
over	O
prior	O
versions	O
.	O
</s>
<s>
A	O
dfn	O
is	O
a	O
sequence	O
of	O
possibly	O
guarded	B-Language
expressions	I-Language
(	O
or	O
just	O
a	O
guard	O
)	O
between	O
and	O
,	O
separated	O
by	O
or	O
new-lines	O
,	O
wherein	O
denotes	O
the	O
left	O
argument	O
and	O
the	O
right	O
,	O
and	O
denotes	O
recursion	O
(	O
function	O
self-reference	O
)	O
.	O
</s>
<s>
The	O
rules	O
for	O
dfns	B-Application
are	O
summarized	O
by	O
the	O
following	O
"	O
reference	O
card	O
"	O
:	O
</s>
<s>
A	O
dfn	O
is	O
a	O
sequence	O
of	O
possibly	O
guarded	B-Language
expressions	I-Language
(	O
or	O
just	O
a	O
guard	O
)	O
between	O
and	O
,	O
separated	O
by	O
or	O
new-lines	O
.	O
</s>
<s>
If	O
occurs	O
in	O
the	O
definition	O
,	O
then	O
the	O
dfn	O
is	O
a	O
dyadic	O
operator	B-Language
;	O
if	O
only	O
occurs	O
but	O
not	O
,	O
then	O
it	O
is	O
a	O
monadic	O
operator	B-Language
;	O
if	O
neither	O
or	O
occurs	O
,	O
then	O
the	O
dfn	O
is	O
a	O
function	O
.	O
</s>
<s>
denotes	O
recursion	O
or	O
self-reference	O
by	O
the	O
function	O
,	O
and	O
denotes	O
self-reference	O
by	O
the	O
operator	B-Language
.	O
</s>
<s>
Such	O
denotation	O
permits	O
anonymous	B-Language
recursion	I-Language
.	O
</s>
<s>
Error	B-General_Concept
trapping	I-General_Concept
is	O
provided	O
through	O
error-guards	O
,	O
.	O
</s>
<s>
Additional	O
descriptions	O
,	O
explanations	O
,	O
and	O
tutorials	O
on	O
dfns	B-Application
are	O
available	O
in	O
the	O
cited	O
articles	O
.	O
</s>
<s>
The	O
examples	O
here	O
illustrate	O
different	O
aspects	O
of	O
dfns	B-Application
.	O
</s>
<s>
uses	O
two	O
different	O
methods	O
to	O
mark	O
composites	O
with	O
0s	O
,	O
both	O
effected	O
using	O
local	O
anonymous	B-General_Concept
dfns	B-Application
:	O
The	O
first	O
uses	O
the	B-Algorithm
sieve	I-Algorithm
of	I-Algorithm
Eratosthenes	I-Algorithm
on	O
an	O
initial	O
mask	O
of	O
1	O
and	O
a	O
prefix	O
of	O
the	O
primes	O
23	O
...	O
43	O
,	O
using	O
the	O
insert	O
operator	B-Language
(	O
right	B-Application
fold	I-Application
)	O
.	O
</s>
<s>
This	O
second	O
dfn	O
uses	O
tail	B-Language
recursion	I-Language
.	O
</s>
<s>
Typically	O
,	O
the	O
factorial	O
function	O
is	O
define	O
recursively	O
(	O
as	O
above	O
)	O
,	O
but	O
it	O
can	O
be	O
coded	O
to	O
exploit	O
tail	B-Language
recursion	I-Language
by	O
using	O
an	O
accumulator	O
left	O
argument	O
:	O
</s>
<s>
Similarly	O
,	O
the	O
determinant	O
of	O
a	O
square	O
complex	O
matrix	O
using	O
Gaussian	B-Algorithm
elimination	I-Algorithm
can	O
be	O
computed	O
with	O
tail	B-Language
recursion	I-Language
:	O
</s>
<s>
The	O
compute	O
time	O
can	O
be	O
reduced	O
by	O
memoization	O
,	O
here	O
implemented	O
as	O
the	O
direct	O
operator	B-Language
(	O
higher-order	B-Language
function	I-Language
)	O
:	O
</s>
<s>
The	O
memo	O
operator	B-Language
defines	O
a	O
variant	O
of	O
its	O
operand	O
function	O
to	O
use	O
a	O
cache	B-General_Concept
and	O
then	O
evaluates	O
it	O
.	O
</s>
<s>
Quicksort	B-Algorithm
on	O
an	O
array	O
works	O
by	O
choosing	O
a	O
"	O
pivot	O
"	O
at	O
random	O
among	O
its	O
major	O
cells	O
,	O
then	O
catenating	O
the	O
sorted	O
major	O
cells	O
which	O
strictly	O
precede	O
the	O
pivot	O
,	O
the	O
major	O
cells	O
equal	O
to	O
the	O
pivot	O
,	O
and	O
the	O
sorted	O
major	O
cells	O
which	O
strictly	O
follow	O
the	O
pivot	O
,	O
as	O
determined	O
by	O
a	O
comparison	O
function	O
.	O
</s>
<s>
Defined	O
as	O
a	O
direct	O
operator	B-Language
(	O
dop	O
)	O
:	O
</s>
<s>
However	O
,	O
unlike	O
the	O
pidgin	B-Language
ALGOL	I-Language
program	O
in	O
Figure	O
3.7	O
,	O
is	O
executable	O
,	O
and	O
the	O
partial	O
order	O
used	O
in	O
the	O
sorting	O
is	O
an	O
operand	O
,	O
the	O
the	O
examples	O
above	O
.	O
</s>
<s>
Dfns	B-Application
,	O
especially	O
anonymous	B-General_Concept
dfns	B-Application
,	O
work	O
well	O
with	O
operators	O
and	O
trains	O
.	O
</s>
<s>
The	O
algorithm	O
works	O
by	O
sorting	O
the	O
rows	O
individually	O
(	O
)	O
,	O
and	O
these	O
sorted	O
rows	O
are	O
used	O
as	O
keys	O
(	O
"	O
signature	O
"	O
in	O
the	O
Programming	O
Pearls	O
description	O
)	O
to	O
the	O
key	O
operator	B-Language
to	O
group	O
the	O
rows	O
of	O
the	O
matrix	O
.	O
</s>
<s>
The	O
expression	O
on	O
the	O
right	O
is	O
a	O
train	O
,	O
a	O
syntactic	O
form	O
employed	O
by	O
APL	B-Language
to	O
achieve	O
tacit	B-Application
programming	I-Application
.	O
</s>
<s>
When	O
an	O
inner	O
(	O
nested	O
)	O
dfn	O
refers	O
to	O
a	O
name	O
,	O
it	O
is	O
sought	O
by	O
looking	O
outward	O
through	O
enclosing	O
dfns	B-Application
rather	O
than	O
down	O
the	O
call	B-General_Concept
stack	I-General_Concept
.	O
</s>
<s>
This	O
regime	O
is	O
said	O
to	O
employ	O
lexical	O
scope	O
instead	O
of	O
APL	B-Language
's	O
usual	O
dynamic	O
scope	O
.	O
</s>
<s>
In	O
APL	B-Language
,	O
error	O
number	O
5	O
is	O
"	O
length	O
error	O
"	O
;	O
error	O
number	O
11	O
is	O
"	O
domain	O
error	O
"	O
;	O
and	O
error	O
number	O
0	O
is	O
a	O
"	O
catch	O
all	O
"	O
for	O
error	O
numbers	O
1	O
to	O
999	O
.	O
</s>
<s>
Since	O
direct	B-Application
functions	I-Application
are	O
dfns	B-Application
,	O
APL	B-Language
functions	O
defined	O
in	O
the	O
traditional	O
manner	O
are	O
referred	O
to	O
as	O
tradfns	O
,	O
pronounced	O
"	O
trad	O
funs	O
"	O
.	O
</s>
<s>
Here	O
,	O
dfns	B-Application
and	O
tradfns	O
are	O
compared	O
by	O
consideration	O
of	O
the	O
function	O
:	O
On	O
the	O
left	O
is	O
a	O
dfn	O
(	O
as	O
defined	O
above	O
)	O
;	O
in	O
the	O
middle	O
is	O
a	O
tradfn	O
using	O
control	O
structures	O
;	O
on	O
the	O
right	O
is	O
a	O
tradfn	O
using	O
gotos	O
(	O
)	O
and	O
line	O
labels	O
.	O
</s>
<s>
A	O
dfn	O
can	O
be	O
anonymous	B-General_Concept
;	O
a	O
tradfn	O
must	O
be	O
named	O
.	O
</s>
<s>
Locals	O
in	O
a	O
dfn	O
have	O
lexical	O
scope	O
;	O
locals	O
in	O
a	O
tradfn	O
have	O
dynamic	O
scope	O
,	O
visible	O
in	O
called	O
functions	O
unless	O
shadowed	B-Language
by	O
their	O
locals	O
list	O
.	O
</s>
<s>
Flow	O
control	O
in	O
a	O
dfn	O
is	O
effected	O
by	O
guards	O
and	O
function	O
calls	O
;	O
that	O
in	O
a	O
tradfn	O
is	O
by	O
control	O
structures	O
and	O
(	O
goto	B-Application
)	O
and	O
line	O
labels	O
.	O
</s>
<s>
Evaluating	O
an	O
expression	O
in	O
a	O
dfn	O
not	O
ending	O
in	O
assignment	O
causes	O
return	O
from	O
the	O
dfn	O
;	O
evaluating	O
a	O
line	O
in	O
a	O
tradfn	O
not	O
ending	O
in	O
assignment	O
or	O
goto	B-Application
displays	O
the	O
result	O
of	O
the	O
line	O
.	O
</s>
<s>
A	O
dfn	O
returns	O
on	O
evaluating	O
an	O
expression	O
not	O
ending	O
in	O
assignment	O
,	O
on	O
evaluating	O
a	O
guarded	O
expression	O
,	O
or	O
after	O
the	O
last	O
expression	O
;	O
a	O
tradfn	O
returns	O
on	O
(	O
goto	B-Application
)	O
line	O
0	O
or	O
a	O
non-existing	O
line	O
,	O
or	O
on	O
evaluating	O
a	O
control	O
structure	O
,	O
or	O
after	O
the	O
last	O
line	O
.	O
</s>
<s>
The	O
simpler	O
flow	O
control	O
in	O
a	O
dfn	O
makes	O
it	O
easier	O
to	O
detect	O
and	O
implement	O
tail	B-Language
recursion	I-Language
than	O
in	O
a	O
tradfn	O
.	O
</s>
<s>
Kenneth	O
E	O
.	O
Iverson	O
,	O
the	O
inventor	O
of	O
APL	B-Language
,	O
was	O
dissatisfied	O
with	O
the	O
way	O
user	O
functions	O
(	O
tradfns	O
)	O
were	O
defined	O
.	O
</s>
<s>
Of	O
these	O
,	O
the	O
"	O
alternative	O
APL	B-Language
function	O
definition	O
"	O
of	O
Bunda	O
in	O
1987	O
came	O
closest	O
to	O
current	O
facilities	O
,	O
but	O
is	O
flawed	O
in	O
conflicts	O
with	O
existing	O
symbols	O
and	O
in	O
error	B-General_Concept
handling	I-General_Concept
which	O
would	O
have	O
caused	O
practical	O
difficulties	O
,	O
and	O
was	O
never	O
implemented	O
.	O
</s>
<s>
The	O
main	O
distillates	O
from	O
the	O
different	O
proposals	O
were	O
that	O
(	O
a	O
)	O
the	O
function	O
being	O
defined	O
is	O
anonymous	B-General_Concept
,	O
with	O
subsequent	O
naming	O
(	O
if	O
required	O
)	O
being	O
effected	O
by	O
assignment	O
;	O
(	O
b	O
)	O
the	O
function	O
is	O
denoted	O
by	O
a	O
symbol	O
and	O
thereby	O
enables	O
anonymous	B-Language
recursion	I-Language
.	O
</s>
<s>
In	O
1996	O
,	O
John	B-Application
Scholes	I-Application
of	O
Dyalog	O
Limited	O
invented	O
direct	B-Application
functions	I-Application
(	O
dfns	B-Application
)	O
.	O
</s>
<s>
The	O
ideas	O
originated	O
in	O
1989	O
when	O
he	O
read	O
a	O
special	O
issue	O
of	O
The	O
Computer	O
Journal	O
on	O
functional	B-Language
programming	I-Language
.	O
</s>
<s>
He	O
then	O
proceeded	O
to	O
study	O
functional	B-Language
programming	I-Language
and	O
became	O
strongly	O
motivated	O
(	O
"	O
sick	O
with	O
desire	O
"	O
,	O
like	O
Yeats	O
)	O
to	O
bring	O
these	O
ideas	O
to	O
APL	B-Language
.	O
</s>
<s>
Dfns	B-Application
were	O
first	O
presented	O
in	O
the	O
Dyalog	O
Vendor	O
Forum	O
at	O
the	O
APL	B-Language
'	O
96	O
Conference	O
and	O
released	O
in	O
Dyalog	O
APL	B-Language
in	O
early	O
1997	O
.	O
</s>
<s>
As	O
late	O
as	O
2008	O
,	O
in	O
Dyalog	O
at	O
25	O
,	O
a	O
publication	O
celebrating	O
the	O
25th	O
anniversary	O
of	O
Dyalog	O
Limited	O
,	O
dfns	B-Application
were	O
barely	O
mentioned	O
(	O
mentioned	O
twice	O
as	O
"	O
dynamic	O
functions	O
"	O
and	O
without	O
elaboration	O
)	O
.	O
</s>
<s>
As	O
of	O
2019	O
,	O
dfns	B-Application
are	O
implemented	O
in	O
Dyalog	O
APL	B-Language
,	O
NARS2000	O
,	O
and	O
ngn/apl	O
.	O
</s>
<s>
They	O
also	O
play	O
a	O
key	O
role	O
in	O
efforts	O
to	O
exploit	O
the	O
computing	O
abilities	O
of	O
a	O
graphics	B-Architecture
processing	I-Architecture
unit	I-Architecture
(	O
GPU	B-Architecture
)	O
.	O
</s>
