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 (2)¶
Every input below was run against the current Mathilda build and its output recorded.
Applications (2)¶
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.
References¶
- Source:
src/core.c - Specification:
docs/spec/builtins/assignment-and-rules.md - Tests:
tests/test_intrat.c - Tests:
tests/test_linalg.c - Tests:
tests/test_linearsolve.c - Tests:
tests/test_matinv_methods.c
Notes & additional examples¶
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.