# Variable calculation

So basically I have some code like this:

Manipulate[
With[{
a = h + 5,
b = a/2
}], {h, -10, 10}]


It works fine for a but doesn't calculate the value of b. the output for b is simply a/2, whatever I change h to has no effect on it.

Beside that the body of your With is missing, you are making a basic mistake: You assume that you can use a inside the definition braces, when you just defined a there. This does not work.

You need to nest two With constructs to do this

Manipulate[With[{a = h + 5},
With[{b = a/2},
{a, b}]
], {h, -10, 10}]


or since version 10 or so, you can use this form (which is shown in red but that is only due to the missing support of the highlighting):

Manipulate[
With[{a = h + 5}, {b = a/2}, {a, b}],
{h, -10, 10}
]

• I tried it and indeed it works, but where is that form of With documented? Has Wolfram committed to this? – Alan Oct 22 '16 at 3:51
• As far as I know this is an undocumented feature. Although it is really handy, the highlighter makes it impossible to use since I cannot stand when some 20 lines of correct code are marked red :) But I thought, I let you know. – halirutan Oct 22 '16 at 4:05
• @Alan Undocumented. See: mathematica.stackexchange.com/a/121173/121 – Mr.Wizard Oct 22 '16 at 11:52