Search⌘ K
AI Features

Parameter Qualifiers: lazy, scope and shared

Explore how parameter qualifiers like lazy, scope, shared, and return modify function arguments in D. Understand eager versus lazy evaluation, thread safety, scope limitations, and lifetime management to avoid bugs and improve program efficiency.

We'll cover the following...

lazy

It is natural to expect that arguments are evaluated before entering the functions that use the arguments. For example, the function add() below is called with the return values of two other functions:

result = add(anAmount(), anotherAmount());

In order for add() to be called, first anAmount() and anotherAmount() must be called. Otherwise, the values that add() needs would not be available.

Evaluating arguments before calling a function is called eager evaluation.

However, depending on certain conditions, some parameters may not get a chance to be used in the function at all. In such cases, evaluating the arguments eagerly would be wasteful.

A classic example of ...