\Header{delay}{Delay Evaluation}
\keyword{programming}{delay}
\keyword{data}{delay}
\begin{Description}\relax
\code{delay} creates a \emph{promise} to evaluate the given
expression in the specified environment if its value is requested.
This provides direct access to \emph{lazy evaluation} mechanism
used by \R{} for the evaluation of (interpreted) functions.
\end{Description}
\begin{Usage}
\begin{verbatim}
delay(x, env=.GlobalEnv)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] an expression.
\item[\code{env}] an evaluation environment
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This is an experimental feature and its addition is purely
for evaluation purposes.
\end{Details}
\begin{Value}
A \emph{promise} to evaluate the expression.
The value which is returned by \code{delay} can be assigned
without forcing its evaluation, but any further accesses
will cause evaluation.
\end{Value}
\begin{Examples}
\begin{ExampleCode}
x <- delay({
    for(i in 1:7)
        cat("yippee!\n")
    10
})

x^2 #- yippee
x^2 #- simple number
\end{ExampleCode}
\end{Examples}

