Lazy Evaluation Definition & Meaning

In programming language theory, lazy evaluation is an evaluation strategy that delays the evaluation of an expression until its value is needed and avoids repeated evaluations. Evaluation is the process of getting the root meaning of a piece of code. Many programming languages evaluate expressions immediately, but it can become inefficient as not all expressions are worth evaluating. The opposite of lazy evaluation is strict evaluation, in which an expression is evaluated immediately.

Lazy evaluation is used in combination with memoization, which is an optimization technique used to speed up computer programs by storing results of function calls and returning the cached results when the same inputs occur again. After a function’s value is computed for the parameter, the result is stored in a table that is indexed by the values of the parameter. The next time the function is called, the table is used to determine whether the result of that combination of parameter values is available. If it is, the stored result is returned. If not, the function is evaluated and another entry is added to the table for reuse.

Haskell is a programming language that has fundamentals based on lazy evaluation.

Lazy evaluation benefits

Benefits of lazy evaluation include:

  • Reducing the time complexity of an algorithm by discarding temporary computations and conditionals
  • Allowing the programmer to define potentially infinite data structures
  • Increasing performance by avoiding unnecessary calculations and avoiding error conditions when evaluating compound expressions
  • Reducing the memory footprint since values are created only when needed

While lazy evaluation is beneficial, it does have its drawbacks. It can be difficult to combine with essential features such as exception handling and input/output because the order of operations becomes indeterminate. Lazy evaluation can also introduce memory leaks.

Top Articles

The Complete List of Text Abbreviations & Acronyms

From A3 to ZZZ we list 1,559 text message and online chat abbreviations to help you translate and understand today's texting lingo. Includes Top...

How to Create a Website Shortcut on Your Desktop

This Webopedia guide will show you how to create a desktop shortcut to a website using Firefox, Chrome or Internet Explorer (IE). Creating a desktop...

Windows Operating System History & Versions

The Windows operating system (Windows OS) refers to a family of operating systems developed by Microsoft Corporation. We look at the history of Windows...

Hotmail [Outlook] Email Accounts

By Vangie Beal Hotmail was one of the first public webmail services that could be accessed from any web browser. Since 2011, Hotmail, in terms...

Data Corruption Definition &...

Data corruption is the process of data becoming unreadable or invalid. It typically...

Subschema Definition & Meaning

A subschema is a database view that filters or organizes all data to...

Fileless Malware Meaning &...

Fileless malware is a type of malicious software that uses legitimate applications already...