Concept:
Eager evaluation
Headline
Evaluate an expression as soon as it gets assigned or passed
Description
This is a very much simplified description. In a language with eager evaluation, each function (or method) application is evaluated such that the arguments are evaluated prior to invoking the body of the function (the method).
Illustration
Eager evaluation in Java
The following code throws NullPointerException because Java uses eager evaluation.
import java.util.LinkedList;
public class Demo {
public static void noOp(int x) {
// I don't care about my argument.
}
public static void main(String[] args) {
LinkedList<String> l = null;
noOp(l.size());
}
}
Arguably, the execution should not throw because the argument is not needed anyway, but that's simply not the semantics of eager evaluation.
Lazy evaluation in Haskell
The de-facto counterpart in Haskell will not throw an exception because the argument of noOp will simply not be evaluated, as it is never needed.
noOp :: Int -> IO ()
noOp _ = return ()
main = noOp (length (undefined::[String]))
This example should not be considered a good example of why laziness is interesting from a programming perspective. The example is merely meant to hint at the semantics of laziness.
Relationshhips
These are synonyms for eager evaluation (in a broad sense):
See lazy evaluation for another major evaluation strategy.There are no revisions for this page.
User contributions
User edits
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.