Lazy Evaluation

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.

Webopedia Staff
Webopedia Staff
Since 1995, more than 100 tech experts and researchers have kept Webopedia’s definitions, articles, and study guides up to date. For more information on current editorial staff, please visit our About page.
Get the Free Newsletter
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.
Get the Free Newsletter
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.

Related Articles

Embedded Analytics

Embedded analytics brings self-service business intelligence to everyday application users.

HRIS

Human resources information system (HRIS) solutions help businesses manage multiple facets of their workforce operations. They provide a central platform for human resources professionals...

Complete List of Cybersecurity Acronyms

Cybersecurity news and best practices are full of acronyms and abbreviations. Without understanding what each one means, it's difficult to comprehend the significance of...

Human Resources Management System

A Human Resources Management System (HRMS) is a software application that supports many functions of a company's Human Resources department, including benefits administration, payroll,...

ScalaHosting

ScalaHosting is a leading managed hosting provider that offers secure, scalable, and affordable...

HRIS

Human resources information system (HRIS) solutions help businesses manage multiple facets of their...

Best Managed Service Providers...

In today's business world, managed services are more critical than ever. They can...