<s>
Lambda	B-Application
lifting	I-Application
is	O
a	O
meta-process	B-Application
that	O
restructures	O
a	O
computer	B-Application
program	I-Application
so	O
that	O
functions	O
are	O
defined	O
independently	O
of	O
each	O
other	O
in	O
a	O
global	O
scope	B-Language
.	O
</s>
<s>
Moving	O
functions	O
from	O
a	O
restricted	O
scope	B-Language
to	O
broader	O
or	O
global	O
scope	B-Language
.	O
</s>
<s>
The	O
term	O
"	O
lambda	B-Application
lifting	I-Application
"	O
was	O
first	O
introduced	O
by	O
Thomas	O
Johnsson	O
around	O
1982	O
and	O
was	O
historically	O
considered	O
as	O
a	O
mechanism	O
for	O
implementing	O
functional	B-Language
programming	I-Language
languages	I-Language
.	O
</s>
<s>
It	O
is	O
used	O
in	O
conjunction	O
with	O
other	O
techniques	O
in	O
some	O
modern	O
compilers	B-Language
.	O
</s>
<s>
Lambda	B-Application
lifting	I-Application
is	O
not	O
the	O
same	O
as	O
closure	B-Application
conversion	I-Application
.	O
</s>
<s>
It	O
requires	O
all	O
call	B-Language
sites	I-Language
to	O
be	O
adjusted	O
(	O
adding	O
extra	O
arguments	O
to	O
calls	O
)	O
and	O
does	O
not	O
introduce	O
a	O
closure	B-Language
for	O
the	O
lifted	O
lambda	O
expression	O
.	O
</s>
<s>
In	O
contrast	O
,	O
closure	B-Application
conversion	I-Application
does	O
not	O
require	O
call	B-Language
sites	I-Language
to	O
be	O
adjusted	O
but	O
does	O
introduce	O
a	O
closure	B-Language
for	O
the	O
lambda	O
expression	O
mapping	O
free	O
variables	O
to	O
values	O
.	O
</s>
<s>
The	O
technique	O
may	O
be	O
used	O
on	O
individual	O
functions	O
,	O
in	O
code	O
refactoring	O
,	O
to	O
make	O
a	O
function	O
usable	O
outside	O
the	O
scope	B-Language
in	O
which	O
it	O
was	O
written	O
.	O
</s>
<s>
Lambda	B-Application
lifts	I-Application
may	O
also	O
be	O
repeated	O
,	O
in	O
order	O
to	O
transform	O
the	O
program	O
.	O
</s>
<s>
Repeated	O
lifts	O
may	O
be	O
used	O
to	O
convert	O
a	O
program	O
written	O
in	O
lambda	B-Language
calculus	I-Language
into	O
a	O
set	O
of	O
recursive	O
functions	O
,	O
without	O
lambdas	O
.	O
</s>
<s>
This	O
demonstrates	O
the	O
equivalence	O
of	O
programs	O
written	O
in	O
lambda	B-Language
calculus	I-Language
and	O
programs	O
written	O
as	O
functions	O
.	O
</s>
<s>
However	O
it	O
does	O
not	O
demonstrate	O
the	O
soundness	O
of	O
lambda	B-Language
calculus	I-Language
for	O
deduction	O
,	O
as	O
the	O
eta	O
reduction	O
used	O
in	O
lambda	B-Application
lifting	I-Application
is	O
the	O
step	O
that	O
introduces	O
cardinality	O
problems	O
into	O
the	O
lambda	B-Language
calculus	I-Language
,	O
because	O
it	O
removes	O
the	O
value	O
from	O
the	O
variable	O
,	O
without	O
first	O
checking	O
that	O
there	O
is	O
only	O
one	O
value	O
that	O
satisfies	O
the	O
conditions	O
on	O
the	O
variable	O
(	O
see	O
Curry	O
's	O
paradox	O
)	O
.	O
</s>
<s>
Lambda	B-Application
lifting	I-Application
is	O
expensive	O
on	O
processing	O
time	O
for	O
the	O
compiler	B-Language
.	O
</s>
<s>
An	O
efficient	O
implementation	O
of	O
lambda	B-Application
lifting	I-Application
is	O
on	O
processing	O
time	O
for	O
the	O
compiler	B-Language
.	O
</s>
<s>
In	O
the	O
untyped	B-Language
lambda	I-Language
calculus	I-Language
,	O
where	O
the	O
basic	O
types	O
are	O
functions	O
,	O
lifting	O
may	O
change	O
the	O
result	O
of	O
beta	B-Language
reduction	I-Language
of	O
a	O
lambda	O
expression	O
.	O
</s>
<s>
The	O
resulting	O
functions	O
will	O
have	O
the	O
same	O
meaning	O
,	O
in	O
a	O
mathematical	O
sense	O
,	O
but	O
are	O
not	O
regarded	O
as	O
the	O
same	O
function	O
in	O
the	O
untyped	B-Language
lambda	I-Language
calculus	I-Language
.	O
</s>
<s>
The	O
reverse	O
operation	O
to	O
lambda	B-Application
lifting	I-Application
is	O
lambda	O
dropping	O
.	O
</s>
<s>
Lambda	O
dropping	O
may	O
make	O
the	O
compilation	B-Language
of	O
programs	O
quicker	O
for	O
the	O
compiler	B-Language
,	O
and	O
may	O
also	O
increase	O
the	O
efficiency	O
of	O
the	O
resulting	O
program	O
,	O
by	O
reducing	O
the	O
number	O
of	O
parameters	O
,	O
and	O
reducing	O
the	O
size	O
of	O
stack	B-Application
frames	O
.	O
</s>
<s>
The	O
following	O
algorithm	O
is	O
one	O
way	O
to	O
lambda-lift	O
an	O
arbitrary	O
program	O
in	O
a	O
language	O
which	O
does	O
n't	O
support	O
closures	B-Language
as	O
first-class	O
objects	O
:	O
</s>
<s>
If	O
the	O
language	O
has	O
closures	B-Language
as	O
first-class	O
objects	O
that	O
can	O
be	O
passed	O
as	O
arguments	O
or	O
returned	O
from	O
other	O
functions	O
,	O
the	O
closure	B-Language
will	O
need	O
to	O
be	O
represented	O
by	O
a	O
data	O
structure	O
that	O
captures	O
the	O
bindings	O
of	O
the	O
free	O
variables	O
.	O
</s>
<s>
The	O
following	O
OCaml	B-Language
program	O
computes	O
the	O
sum	O
of	O
the	O
integers	O
from	O
1	O
to	O
100	O
:	O
</s>
<s>
The	O
following	O
is	O
the	O
same	O
example	O
,	O
this	O
time	O
written	O
in	O
JavaScript	B-Language
:	O
</s>
<s>
Lambda	B-Application
lifting	I-Application
and	O
closure	B-Language
are	O
both	O
methods	O
for	O
implementing	O
block	O
structured	O
programs	O
.	O
</s>
<s>
Closure	B-Application
conversion	I-Application
provides	O
a	O
"	O
closure	B-Language
"	O
which	O
links	O
the	O
current	O
frame	O
to	O
other	O
frames	O
.	O
</s>
<s>
Closure	B-Application
conversion	I-Application
takes	O
less	O
compile	B-Language
time	O
.	O
</s>
<s>
Recursive	O
functions	O
,	O
and	O
block	O
structured	O
programs	O
,	O
with	O
or	O
without	O
lifting	O
,	O
may	O
be	O
implemented	O
using	O
a	O
stack	B-Application
based	O
implementation	O
,	O
which	O
is	O
simple	O
and	O
efficient	O
.	O
</s>
<s>
However	O
a	O
stack	B-Application
frame	O
based	O
implementation	O
must	O
be	O
strict	O
(	O
eager	O
)	O
.	O
</s>
<s>
The	O
stack	B-Application
frame	O
based	O
implementation	O
requires	O
that	O
the	O
life	O
of	O
functions	O
be	O
last-in	B-Application
,	I-Application
first-out	I-Application
(	O
LIFO	B-Application
)	O
.	O
</s>
<s>
Some	O
functional	B-Language
languages	I-Language
(	O
such	O
as	O
Haskell	B-Language
)	O
are	O
implemented	O
using	O
lazy	O
evaluation	O
,	O
which	O
delays	O
calculation	O
until	O
the	O
value	O
is	O
needed	O
.	O
</s>
<s>
The	O
"	O
frame	O
"	O
is	O
similar	O
to	O
a	O
stack	B-Application
frame	O
,	O
the	O
difference	O
being	O
that	O
it	O
is	O
not	O
stored	O
on	O
the	O
stack	B-Application
.	O
</s>
<s>
If	O
the	O
function	O
is	O
"	O
lifted	O
"	O
,	O
then	O
the	O
frame	O
needs	O
only	O
record	O
the	O
function	B-Language
pointer	I-Language
,	O
and	O
the	O
parameters	O
to	O
the	O
function	O
.	O
</s>
<s>
Some	O
modern	O
languages	O
use	O
garbage	B-General_Concept
collection	I-General_Concept
in	O
place	O
of	O
stack	B-Application
based	O
allocation	O
to	O
manage	O
the	O
life	O
of	O
variables	O
.	O
</s>
<s>
In	O
a	O
managed	O
,	O
garbage	B-General_Concept
collected	I-General_Concept
environment	O
,	O
a	O
closure	B-Language
records	O
references	O
to	O
the	O
frames	O
from	O
which	O
values	O
may	O
be	O
obtained	O
.	O
</s>
<s>
The	O
Let	B-Application
expression	I-Application
is	O
useful	O
in	O
describing	O
lifting	O
and	O
dropping	O
,	O
and	O
in	O
describing	O
the	O
relationship	O
between	O
recursive	O
equations	O
and	O
lambda	O
expressions	O
.	O
</s>
<s>
Most	O
functional	B-Language
languages	I-Language
have	O
let	B-Application
expressions	I-Application
.	O
</s>
<s>
Also	O
,	O
block	O
structured	O
programming	O
languages	O
like	O
ALGOL	B-Language
and	O
Pascal	B-Application
are	O
similar	O
in	O
that	O
they	O
too	O
allow	O
the	O
local	O
definition	O
of	O
a	O
function	O
for	O
use	O
in	O
a	O
restricted	O
scope	B-Language
.	O
</s>
<s>
The	O
let	B-Application
expression	I-Application
used	O
here	O
is	O
a	O
fully	O
mutually	O
recursive	O
version	O
of	O
let	O
rec	O
,	O
as	O
implemented	O
in	O
many	O
functional	B-Language
languages	I-Language
.	O
</s>
<s>
Let	B-Application
expressions	I-Application
are	O
related	O
to	O
Lambda	B-Language
calculus	I-Language
.	O
</s>
<s>
Lambda	B-Language
calculus	I-Language
has	O
a	O
simple	O
syntax	O
and	O
semantics	O
,	O
and	O
is	O
good	O
for	O
describing	O
Lambda	B-Application
lifting	I-Application
.	O
</s>
<s>
It	O
is	O
convenient	O
to	O
describe	O
lambda	B-Application
lifting	I-Application
as	O
a	O
translations	O
from	O
lambda	O
to	O
a	O
let	B-Application
expression	I-Application
,	O
and	O
lambda	O
dropping	O
as	O
the	O
reverse	O
.	O
</s>
<s>
This	O
is	O
because	O
let	B-Application
expressions	I-Application
allow	O
mutual	O
recursion	O
,	O
which	O
is	O
,	O
in	O
a	O
sense	O
,	O
more	O
lifted	O
than	O
is	O
supported	O
in	O
lambda	B-Language
calculus	I-Language
.	O
</s>
<s>
Lambda	B-Language
calculus	I-Language
does	O
not	O
support	O
mutual	O
recursion	O
and	O
only	O
one	O
function	O
may	O
be	O
defined	O
at	O
the	O
outermost	O
global	O
scope	B-Language
.	O
</s>
<s>
Conversion	O
rules	O
which	O
describe	O
translation	O
without	O
lifting	O
are	O
given	O
in	O
the	O
Let	B-Application
expression	I-Application
article	O
.	O
</s>
<s>
The	O
following	O
rules	O
describe	O
the	O
equivalence	O
of	O
lambda	O
and	O
let	B-Application
expressions	I-Application
,	O
</s>
<s>
Meta-functions	O
will	O
be	O
given	O
that	O
describe	O
lambda	B-Application
lifting	I-Application
and	O
dropping	O
.	O
</s>
<s>
The	O
rules	O
also	O
assume	O
that	O
the	O
lambda	O
expressions	O
have	O
been	O
pre-processed	O
so	O
that	O
each	O
lambda	B-Language
abstraction	I-Language
has	O
a	O
unique	O
name	O
.	O
</s>
<s>
The	O
definition	O
used	O
is	O
extended	O
to	O
cover	O
the	O
substitution	O
of	O
expressions	O
,	O
from	O
the	O
definition	O
given	O
on	O
the	O
Lambda	B-Language
calculus	I-Language
page	O
.	O
</s>
<s>
Each	O
lambda	B-Application
lift	I-Application
takes	O
a	O
lambda	B-Language
abstraction	I-Language
which	O
is	O
a	O
sub	O
expression	O
of	O
a	O
lambda	O
expression	O
and	O
replaces	O
it	O
by	O
a	O
function	O
call	O
(	O
application	O
)	O
to	O
a	O
function	O
that	O
it	O
creates	O
.	O
</s>
<s>
Lambda	B-Application
lifts	I-Application
may	O
be	O
used	O
on	O
individual	O
functions	O
,	O
in	O
code	O
refactoring	O
,	O
to	O
make	O
a	O
function	O
usable	O
outside	O
the	O
scope	B-Language
in	O
which	O
it	O
was	O
written	O
.	O
</s>
<s>
Such	O
lifts	O
may	O
also	O
be	O
repeated	O
,	O
until	O
the	O
expression	O
has	O
no	O
lambda	B-Language
abstractions	I-Language
,	O
in	O
order	O
to	O
transform	O
the	O
program	O
.	O
</s>
<s>
The	O
lambda	B-Application
lift	I-Application
operation	O
used	O
to	O
perform	O
a	O
lift	O
within	O
a	O
program	O
is	O
,	O
</s>
<s>
The	O
sub	O
expression	O
may	O
be	O
either	O
a	O
lambda	B-Language
abstraction	I-Language
,	O
or	O
a	O
lambda	B-Language
abstraction	I-Language
applied	O
to	O
a	O
parameter	O
.	O
</s>
<s>
An	O
anonymous	O
lift	O
has	O
a	O
lift	O
expression	O
which	O
is	O
a	O
lambda	B-Language
abstraction	I-Language
only	O
.	O
</s>
<s>
A	O
named	O
lift	O
expression	O
has	O
a	O
lambda	B-Language
abstraction	I-Language
applied	O
to	O
an	O
expression	O
.	O
</s>
<s>
An	O
anonymous	O
lift	O
takes	O
a	O
lambda	B-Language
abstraction	I-Language
(	O
called	O
S	O
)	O
.	O
</s>
<s>
The	O
lambda	B-Application
lift	I-Application
is	O
the	O
substitution	O
of	O
the	O
lambda	B-Language
abstraction	I-Language
S	O
for	O
a	O
function	O
application	O
,	O
along	O
with	O
the	O
addition	O
of	O
a	O
definition	O
for	O
the	O
function	O
.	O
</s>
<s>
See	O
de-lambda	O
in	O
Conversion	O
from	O
lambda	O
to	O
let	B-Application
expressions	I-Application
.	O
</s>
<s>
See	O
de-lambda	O
in	O
Conversion	O
from	O
lambda	O
to	O
let	B-Application
expressions	I-Application
.	O
</s>
<s>
A	O
lambda	B-Application
lift	I-Application
transformation	O
takes	O
a	O
lambda	O
expression	O
and	O
lifts	O
all	O
lambda	B-Language
abstractions	I-Language
to	O
the	O
top	O
of	O
the	O
expression	O
.	O
</s>
<s>
The	O
abstractions	O
are	O
then	O
translated	O
into	O
recursive	O
functions	O
,	O
which	O
eliminates	O
the	O
lambda	B-Language
abstractions	I-Language
.	O
</s>
<s>
The	O
result	O
is	O
a	O
functional	B-Language
program	I-Language
in	O
the	O
form	O
,	O
</s>
<s>
The	O
de-let	O
meta	O
function	O
may	O
then	O
be	O
used	O
to	O
convert	O
the	O
result	O
back	O
into	O
lambda	B-Language
calculus	I-Language
.	O
</s>
<s>
The	O
let	B-Application
expression	I-Application
allows	O
the	O
function	O
definitions	O
to	O
refer	O
to	O
each	O
other	O
directly	O
,	O
whereas	O
lambda	B-Language
abstractions	I-Language
are	O
strictly	O
hierarchical	O
,	O
and	O
a	O
function	O
may	O
not	O
directly	O
refer	O
to	O
itself	O
.	O
</s>
<s>
The	O
first	O
treats	O
all	O
lambda	B-Language
abstractions	I-Language
as	O
defining	O
anonymous	O
functions	O
.	O
</s>
<s>
The	O
second	O
,	O
treats	O
lambda	B-Language
abstractions	I-Language
which	O
are	O
applied	O
to	O
a	O
parameter	O
as	O
defining	O
a	O
function	O
.	O
</s>
<s>
Lambda	B-Language
abstractions	I-Language
applied	O
to	O
a	O
parameter	O
have	O
a	O
dual	O
interpretation	O
as	O
either	O
a	O
let	B-Application
expression	I-Application
defining	O
a	O
function	O
,	O
or	O
as	O
defining	O
an	O
anonymous	O
function	O
.	O
</s>
<s>
lambda-free	O
-	O
An	O
expression	O
containing	O
no	O
lambda	B-Language
abstractions	I-Language
.	O
</s>
<s>
This	O
definition	O
does	O
not	O
recognize	O
a	O
lambda	B-Language
abstractions	I-Language
with	O
a	O
parameter	O
as	O
defining	O
a	O
function	O
.	O
</s>
<s>
All	O
lambda	B-Language
abstractions	I-Language
are	O
regarded	O
as	O
defining	O
anonymous	O
functions	O
.	O
</s>
<s>
This	O
definition	O
recognizes	O
a	O
lambda	B-Language
abstraction	I-Language
with	O
an	O
actual	O
parameter	O
as	O
defining	O
a	O
function	O
.	O
</s>
<s>
Only	O
lambda	B-Language
abstractions	I-Language
without	O
an	O
application	O
are	O
treated	O
as	O
anonymous	O
functions	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
Y	B-Application
combinator	I-Application
,	O
</s>
<s>
If	O
lifting	O
anonymous	O
functions	O
only	O
,	O
the	O
Y	B-Application
combinator	I-Application
is	O
,	O
</s>
<s>
Lambda	O
dropping	O
is	O
making	O
the	O
scope	B-Language
of	O
functions	O
smaller	O
and	O
using	O
the	O
context	O
from	O
the	O
reduced	O
scope	B-Language
to	O
reduce	O
the	O
number	O
of	O
parameters	O
to	O
functions	O
.	O
</s>
<s>
In	O
the	O
Lambda	B-Application
lifting	I-Application
section	O
,	O
a	O
meta	O
function	O
for	O
first	O
lifting	O
and	O
then	O
converting	O
the	O
resulting	O
lambda	O
expression	O
into	O
recursive	O
equation	O
was	O
described	O
.	O
</s>
<s>
The	O
Lambda	O
Drop	O
meta	O
function	O
performs	O
the	O
reverse	O
by	O
first	O
converting	O
recursive	O
equations	O
to	O
lambda	B-Language
abstractions	I-Language
,	O
and	O
then	O
dropping	O
the	O
resulting	O
lambda	O
expression	O
,	O
into	O
the	O
smallest	O
scope	B-Language
which	O
covers	O
all	O
references	O
to	O
the	O
lambda	B-Language
abstraction	I-Language
.	O
</s>
<s>
L	O
is	O
the	O
lambda	B-Language
abstraction	I-Language
to	O
be	O
dropped	O
.	O
</s>
<s>
Sinking	O
is	O
moving	O
a	O
lambda	B-Language
abstraction	I-Language
inwards	O
as	O
far	O
as	O
possible	O
such	O
that	O
it	O
is	O
still	O
outside	O
all	O
references	O
to	O
the	O
variable	O
.	O
</s>
<s>
Lambda	B-Application
lifting	I-Application
added	O
parameters	O
that	O
were	O
necessary	O
so	O
that	O
a	O
function	O
can	O
be	O
moved	O
out	O
of	O
its	O
context	O
.	O
</s>
<s>
The	O
actual	O
parameter	O
for	O
the	O
formal	O
parameter	O
y	O
is	O
always	O
n	O
.	O
However	O
n	O
is	O
bound	O
in	O
a	O
lambda	B-Language
abstraction	I-Language
.	O
</s>
<s>
Let	O
-	O
Let	B-Application
expression	I-Application
.	O
</s>
<s>
Let	O
-	O
Let	B-Application
expression	I-Application
.	O
</s>
<s>
The	O
function	O
definition	O
(	O
lambda	B-Language
abstraction	I-Language
)	O
.	O
</s>
<s>
Which	O
gives	O
back	O
the	O
Y	B-Application
combinator	I-Application
,	O
</s>
