Skip to content

With ​

Substitutes fixed values into an expression before evaluating it.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageWith✓
With({x = x0, y = y0, ...}, body)bodybody with every xx replaced by its (already evaluated) x0x0, then evaluated.
Typed signatures
TypePackageApplies
(any, any) -> anycombinatoricsalways

Domain: Collections

Details
  • The bindings are simultaneous, not sequential — a later binding's value expression cannot see an earlier one in the same WithWith; each is computed against the surrounding context alone. Use nested WithWith for one binding to see the previous.
  • A binding list is {x=x0,y=y0,...}\{x = x0, y = y0, ...\}: as MathJSON, [List,[Equal,x,x0],...][List, [Equal, x, x0], ...] — = parses to EqualEqual, not to compute-engine's own AssignAssign.
  • Unlike Module, WithWith introduces no fresh variable — it is pure substitution, so a name used as an xx never shadows an outer binding beyond the substituted occurrences in bodybody itself.

Examples

Basic #

substitute a fixed value

live ↗
InWith([x=3],xx)\mathrm{With}(\bigl\lbrack x=3\bigr\rbrack, xx)Out99
Scope #

several bindings at once

live ↗
InWith({x=2y=5,x+y)\mathrm{With}(\begin{cases}x=2\\y=5\end{cases}, x+y)Out77
About
Examples2
Checked againstWolfram Language 2 agree
CrosswalkWolfram Language

See also: Module