Controlling Evaluation

🟰Default Evaluation

Example, weight force of a cucumber:

m_cuc = 400 g;

force = m_cuc * _g0force = 3.9226 N

By default, Calcumber evaluates expressions in three steps:

1. Variable substitution → 400 g * 9.80665 m/s^2

2. Arithmetic evaluation → 3922.66 g*m/s^2

3. Unit simplification → 3.92266 N

This behavior can be influenced by the functions eval and lazy.

⚡Eval

The eval function forces another evaluation.

A modified cucumber weight force example:

force = m_cuc * _g0force ➔ m_cuc * 9.80665 m/s^2

m_cuc = 400 g;

forcem_cuc * 9.80665 m/s^2

force is replaced by its definition only

eval(force)3.92266 N eval forces another evaluation

Want to calculate for a smaller cucumber? Just define a local variable as argument for eval.

eval(force, m_cuc = 350 g)3.4323275 N

💤Lazy

The lazy function prevents evaluation.

m_cuc = 400 g; definine the mass

force = m_cuc * _g0force = 3.9226 N

➔ The expression is evaluated and then assinged to force.

force = lazy(m_cuc * _g0force = m_cuc * _g0

➔ The unevaluated expression is assinged to force.

Scroll to Top