Why does this:
Manipulate[test[a_] := 2*b; test[c], {b, 0, 1}, {c, 0, 1}]
turns into an evaluation loop?
Shouldn’t Manipulate only evaluate when b or c changes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, the
Manipulatewill re-evaluate whenborcchanges, but also iftestchanges — andtestis being re-assigned every time any one of those values changes. Hence the endless re-evaluation loop.As a rule, side-effects should be avoided in the display expressions of constructs like
ManipulateandDynamicin order to avoid evaluation loops, race conditions and other surprising behaviour. In the case at hand, I would suggest removing the implicit dependency onbintestand hoisting its definition outside of theManipulate:In the real application, there may be obstacles to such a simple refactoring — but the key point is to remove the
:=from the dynamic expression.