Home

callbyname

Call-by-name is a parameter passing mechanism used in some programming languages in which the actual argument expressions are not evaluated at the time of the call. Instead, each reference to a formal parameter inside the callee is replaced with the corresponding actual expression and evaluated in the caller’s environment every time the parameter is used. This makes the parameter behave like a symbolic alias to the expression rather than a stored value.

Origin and usage

Call-by-name was popularized by the Algol 60 language and is often described in contrast to call-by-value (evaluate

Semantics and implications

Under call-by-name, the argument expression can be evaluated multiple times, potentially with different results if the

Relation to other strategies

Call-by-name is conceptually between substitution-based evaluation and reference-based binding. It contrasts with call-by-value, which fixes a

See also

Call-by-value, call-by-reference, thunks, Algol 60.

arguments
once
before
the
call)
and
call-by-reference
(pass
an
alias
to
the
actual
variable).
Implementations
historically
used
textual
substitution
or
a
mechanism
called
a
thunk,
which
delays
and
re-evaluates
the
expression
in
the
caller’s
context
whenever
the
parameter
is
accessed.
surrounding
state
changes
between
uses.
Side
effects
in
the
argument
expression
are
therefore
observable
each
time
the
parameter
is
evaluated.
If
the
formal
parameter
is
assigned
to
inside
the
callee,
the
effect
can
propagate
back
to
the
actual
parameter
only
when
the
actual
parameter
denotes
a
variable
in
the
caller;
otherwise,
assignments
may
be
illegal
or
have
surprising
effects.
This
evaluation
strategy
can
lead
to
powerful
abstractions
but
also
to
subtle
bugs
and
inefficiencies
due
to
repeated
evaluation.
computed
value
for
the
duration
of
the
call,
and
with
call-by-reference,
which
permits
direct
modification
of
the
caller’s
variables
through
the
callee.