Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Lazy evaluation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Software optimization technique}} {{Evaluation strategy}} In [[programming language theory]], '''lazy evaluation''', or '''call-by-need''',<ref>{{harvnb|Hudak|1989|p=384}}</ref> is an [[evaluation strategy]] which delays the evaluation of an [[Expression (computer science)|expression]] until its value is needed ([[non-strict evaluation]]) and which avoids repeated evaluations (by the use of [[Sharing (computer science)|sharing]]).<ref name="WattFindlay2004">{{cite book|author1=David Anthony Watt|author2=William Findlay|title=Programming language design concepts|url=https://books.google.com/books?id=vogP3P2L4tgC&pg=PA367|access-date=30 December 2010|year=2004|publisher=John Wiley and Sons|isbn=978-0-470-85320-7|pages=367β368}}</ref><ref>{{harvnb|Reynolds|1998|p=307}}</ref> The benefits of lazy evaluation include: * The ability to define [[control flow]] (structures) as abstractions instead of [[Language primitive|primitives]]. * The ability to define [[actual infinity|potentially infinite]] [[data structure]]s. This allows for more straightforward implementation of some [[algorithm]]s. * The ability to define partly-defined data structures where some elements are errors. This allows for rapid prototyping. Lazy evaluation is often combined with [[memoization]], as described in [[Jon Bentley (computer scientist)|Jon Bentley]]'s ''Writing Efficient Programs''.<ref>Bentley, Jon Louis. Writing Efficient Programs. Prentice-Hall, 1985. {{ISBN|978-0139702440}}</ref> After a function's value is computed for that [[Parameter (computer programming)|parameter]] or set of parameters, the result is stored in a [[lookup table]] that is indexed by the values of those parameters; the next time the function is called, the table is consulted to determine whether the result for that combination of parameter values is already available. If so, the stored result is simply returned. If not, the function is evaluated, and another entry is added to the lookup table for reuse. Lazy evaluation is difficult to combine with [[Imperative programming|imperative]] features such as [[exception handling]] and [[input/output]], because the [[order of operations]] becomes indeterminate. The opposite of lazy evaluation is [[eager evaluation]], sometimes known as strict evaluation. Eager evaluation is the evaluation strategy employed in most{{quantify|date=July 2020}} [[programming language]]s.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)