Why does
With[{x0 = 1, y0 = 2},
f[x_] = a + b x /. First[
Solve[{y0 == a + b x0, b == 0.1}, {a, b}]]]
evaluate to
1.9 + 0.1 x$
instead of
1.9 + 0.1 x
?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this community
Details
onWith
and this comment by jkuczm. It's the expected behavior. $\endgroup$f
gets defined as intended. Only the return value ofwith
is odd and you can hide it with a semicolon. $\endgroup$With
statements which is obviously not the case here. Similarly, the linked comment verifies that it's not clear when renaming occurs in nested statements. I think that one seemingly relevant example in section Properties & Relations (the last one) is actually not relevant here; same applies for the examples in the Possible Issues section $\endgroup$With
doesn't care whether the scoping construct isWith
or a function definition. It's all the same thing (lexical rescoping). $\endgroup$