<s>
In	O
mathematics	O
and	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
higher-order	B-Language
function	I-Language
(	O
HOF	O
)	O
is	O
a	O
function	O
that	O
does	O
at	O
least	O
one	O
of	O
the	O
following	O
:	O
</s>
<s>
All	O
other	O
functions	O
are	O
first-order	B-Language
functions	I-Language
.	O
</s>
<s>
In	O
mathematics	O
higher-order	B-Language
functions	I-Language
are	O
also	O
termed	O
operators	O
or	O
functionals	O
.	O
</s>
<s>
The	O
differential	O
operator	O
in	O
calculus	O
is	O
a	O
common	O
example	O
,	O
since	O
it	O
maps	O
a	O
function	O
to	O
its	O
derivative	B-Algorithm
,	O
also	O
a	O
function	O
.	O
</s>
<s>
Higher-order	B-Language
functions	I-Language
should	O
not	O
be	O
confused	O
with	O
other	O
uses	O
of	O
the	O
word	O
"	O
functor	O
"	O
throughout	O
mathematics	O
,	O
see	O
Functor	O
(	O
disambiguation	O
)	O
.	O
</s>
<s>
In	O
the	O
untyped	O
lambda	B-Language
calculus	I-Language
,	O
all	O
functions	O
are	O
higher-order	O
;	O
in	O
a	O
typed	O
lambda	B-Language
calculus	I-Language
,	O
from	O
which	O
most	O
functional	B-Language
programming	I-Language
languages	I-Language
are	O
derived	O
,	O
higher-order	B-Language
functions	I-Language
that	O
take	O
one	O
function	O
as	O
argument	O
are	O
values	O
with	O
types	O
of	O
the	O
form	O
.	O
</s>
<s>
map	O
function	O
,	O
found	O
in	O
many	O
functional	B-Language
programming	I-Language
languages	I-Language
,	O
is	O
one	O
example	O
of	O
a	O
higher-order	B-Language
function	I-Language
.	O
</s>
<s>
The	O
C	B-Language
standard	O
function	O
qsort	B-Language
is	O
an	O
example	O
of	O
this	O
.	O
</s>
<s>
In	O
the	O
following	O
examples	O
,	O
the	O
higher-order	B-Language
function	I-Language
takes	O
a	O
function	O
,	O
and	O
applies	O
the	O
function	O
to	O
some	O
value	O
twice	O
.	O
</s>
<s>
Using	O
in	O
C++11	B-Language
:	O
</s>
<s>
Or	O
,	O
with	O
generic	O
lambdas	B-General_Concept
provided	O
by	O
C++14	O
:	O
</s>
<s>
Or	O
equivalently	O
,	O
with	O
static	B-Language
methods	I-Language
:	O
</s>
<s>
Alternatively	O
,	O
we	O
can	O
also	O
compose	O
using	O
pure	O
anonymous	B-General_Concept
functions	I-General_Concept
.	O
</s>
<s>
In	O
this	O
Erlang	O
example	O
,	O
the	O
higher-order	B-Language
function	I-Language
takes	O
a	O
list	O
of	O
functions	O
(	O
)	O
and	O
argument	O
(	O
)	O
.	O
</s>
<s>
If	O
the	O
function	O
returns	O
the	O
higher-order	B-Language
function	I-Language
will	O
return	O
.	O
</s>
<s>
Notice	O
a	O
function	B-General_Concept
literal	I-General_Concept
can	O
be	O
defined	O
either	O
with	O
an	O
identifier	O
(	O
)	O
or	O
anonymously	O
(	O
assigned	O
to	O
variable	O
)	O
.	O
</s>
<s>
Or	O
equivalently	O
,	O
with	O
static	B-Language
methods	I-Language
:	O
</s>
<s>
With	O
arrow	B-General_Concept
functions	I-General_Concept
:	O
</s>
<s>
Note	O
that	O
arrow	B-General_Concept
functions	I-General_Concept
implicitly	O
capture	O
any	O
variables	O
that	O
come	O
from	O
the	O
parent	O
scope	O
,	O
whereas	O
anonymous	B-General_Concept
functions	I-General_Concept
require	O
the	O
keyword	O
to	O
do	O
the	O
same	O
.	O
</s>
<s>
Python	O
decorator	O
syntax	O
is	O
often	O
used	O
to	O
replace	O
a	O
function	O
with	O
the	O
result	O
of	O
passing	O
that	O
function	O
through	O
a	O
higher-order	B-Language
function	I-Language
.	O
</s>
<s>
Raku	O
also	O
supports	O
"	O
pointy	O
block	O
"	O
syntax	O
for	O
lambda	B-General_Concept
expressions	I-General_Concept
which	O
can	O
be	O
assigned	O
to	O
a	O
variable	O
or	O
invoked	O
anonymously	O
.	O
</s>
<s>
Tcl	O
uses	O
apply	O
command	O
to	O
apply	O
an	O
anonymous	B-General_Concept
function	I-General_Concept
(	O
since	O
8.6	O
)	O
.	O
</s>
<s>
The	O
XACML	O
standard	O
defines	O
higher-order	B-Language
functions	I-Language
in	O
the	O
standard	O
to	O
apply	O
a	O
function	O
to	O
multiple	O
values	O
of	O
attribute	O
bags	O
.	O
</s>
<s>
The	O
list	O
of	O
higher-order	B-Language
functions	I-Language
in	O
XACML	O
can	O
be	O
found	O
here	O
.	O
</s>
<s>
Function	B-Language
pointers	I-Language
in	O
languages	O
such	O
as	O
C	B-Language
,	O
C++	B-Language
,	O
and	O
Pascal	B-Application
allow	O
programmers	O
to	O
pass	O
around	O
references	O
to	O
functions	O
.	O
</s>
<s>
The	O
following	O
C	B-Language
code	O
computes	O
an	O
approximation	O
of	O
the	O
integral	O
of	O
an	O
arbitrary	O
function	O
:	O
</s>
<s>
The	O
qsort	B-Language
function	O
from	O
the	O
C	B-Language
standard	O
library	O
uses	O
a	O
function	B-Language
pointer	I-Language
to	O
emulate	O
the	O
behavior	O
of	O
a	O
higher-order	B-Language
function	I-Language
.	O
</s>
<s>
Macros	O
can	O
also	O
be	O
used	O
to	O
achieve	O
some	O
of	O
the	O
effects	O
of	O
higher-order	B-Language
functions	I-Language
.	O
</s>
<s>
In	O
other	O
imperative	B-Application
programming	I-Application
languages	I-Application
,	O
it	O
is	O
possible	O
to	O
achieve	O
some	O
of	O
the	O
same	O
algorithmic	O
results	O
as	O
are	O
obtained	O
via	O
higher-order	B-Language
functions	I-Language
by	O
dynamically	O
executing	O
code	O
(	O
sometimes	O
called	O
Eval	O
or	O
Execute	O
operations	O
)	O
in	O
the	O
scope	O
of	O
evaluation	O
.	O
</s>
<s>
This	O
string	O
must	O
either	O
be	O
compiled	O
during	O
program	O
execution	O
(	O
using	O
just-in-time	O
compilation	O
)	O
or	O
evaluated	O
by	O
interpretation	B-Application
,	O
causing	O
some	O
added	O
overhead	O
at	O
run-time	O
,	O
and	O
usually	O
generating	O
less	O
efficient	O
code	O
.	O
</s>
<s>
In	O
object-oriented	B-Language
programming	I-Language
languages	I-Language
that	O
do	O
not	O
support	O
higher-order	B-Language
functions	I-Language
,	O
objects	O
can	O
be	O
an	O
effective	O
substitute	O
.	O
</s>
<s>
An	O
object	O
's	O
methods	B-Language
act	O
in	O
essence	O
like	O
functions	O
,	O
and	O
a	O
method	O
may	O
accept	O
objects	O
as	O
parameters	O
and	O
produce	O
objects	O
as	O
return	O
values	O
.	O
</s>
<s>
Languages	O
that	O
permit	O
stack-based	O
(	O
versus	O
heap-based	O
)	O
objects	O
or	O
structs	O
can	O
provide	O
more	O
flexibility	O
with	O
this	O
method	O
.	O
</s>
<s>
An	O
example	O
of	O
using	O
a	O
simple	O
stack	B-General_Concept
based	O
record	O
in	O
Free	B-Operating_System
Pascal	I-Operating_System
with	O
a	O
function	O
that	O
returns	O
a	O
function	O
:	O
</s>
<s>
Defunctionalization	B-Application
can	O
be	O
used	O
to	O
implement	O
higher-order	B-Language
functions	I-Language
in	O
languages	O
that	O
lack	O
first-class	B-Application
functions	I-Application
:	O
</s>
<s>
In	O
this	O
case	O
,	O
different	O
types	O
are	O
used	O
to	O
trigger	O
different	O
functions	O
via	O
function	B-Language
overloading	I-Language
.	O
</s>
<s>
The	O
overloaded	B-Language
function	I-Language
in	O
this	O
example	O
has	O
the	O
signature	O
auto	O
apply	O
.	O
</s>
