Skip to content

CompoundExpression

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

expr1; expr2; ... evaluates its arguments in sequence, returning the last result.

Examples

No verified examples yet for this function.

Implementation notes

Algorithm. builtin_compoundexpression (in src/core.c) walks its argument list in order, calling evaluate() on each expr; clause and freeing the previous result before storing the next, so only the value of the last clause survives. An empty CompoundExpression[] returns the symbol Null. The head carries ATTR_HOLDALL (registered in src/attr.c), so the evaluator does not pre-evaluate the arguments — the builtin evaluates them itself, one at a time, which is what makes a; b; c sequence side effects (e.g. assignments installed by Set) in source order rather than all at once. After each evaluation the result head is inspected for the control-flow markers Return, Break, Continue, Throw, Abort, and Quit; if any is seen the loop breaks early and returns that wrapper unevaluated so an enclosing construct can act on it.

Data structures. Plain iteration over res->data.function.args; a single last_val accumulator holds the running result.

Attributes: HoldAll, Protected.

Implementation status

Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

References

Notes & additional examples

Worked examples

In[1]:= (a = 2; b = 3; a + b)
Out[1]= 5

In[2]:= (x = 10; x^2; x + 1)
Out[2]= 11

Notes

Written with the ; operator, expr1; expr2; ... evaluates each argument in turn and returns the value of the last one (intermediate results are discarded). Wrap a chain in parentheses when you want the final value to print.