4 ms·
Note that you can nest within a single With: With[ {x = 2}, {y = 3}, x + y ] Though this form is not (yet) documented. Crucially, y could ref
by brenton_wri 6y ago
Note that you can nest within a single With:
With[
{x = 2},
{y = 3},
x + y
]
Though this form is not (yet) documented.
Crucially, y could refer to x here.
It can really help with the indentation.
- kmill 6y agoI use notebooks primarily -- it would be nice if syntax highlighting didn't put x+y in scary red :-) Something I've wondered: would it be possible to support With[x = 2, x + x] when there's just a single variable? It's certainly very low-priority, but it saves a few keystrokes when doing quick calculations.
- brenton_wri 6y agoYep, the proper syntax highlighting will follow when documented. There was actually a massive internal discussion in 2015 re: With[x = 2, x + x]. And With[x = 2, x + x] actually did work for a time. Unfortunately, several other ideas like With[x, x+x] and Module[x, x+x] (which was unintuitively NOT implemented as Module[{x}, x+x]) also got thrown into the conversation and things became confused, these uses were seen to be problematic, and soon the baby was thrown out with the bath water. So technically yes, With[x = 2, x + x] could work, but it is unlikely that it will ever be implemented in product.