Timeline for Update a function avoiding infinite recursion
Current License: CC BY-SA 3.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 13, 2017 at 12:55 | history | edited | CommunityBot | replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/ | |
| Mar 22, 2013 at 2:08 | comment | added | Leonid Shifrin | @Stefano Yes, it is expected. Try to figure out on your own why this is so. I also think that whatever your problem is, you should be able to solve it without the rather heavy machinery I described in my post. | |
| Mar 22, 2013 at 1:07 | comment | added | Stefano | Sorry for writing again, but checking further the results, I noticed that some problems are still around. If I try ClearAll[foo] foo[n_] := 2*n - 1; For[i = 0, i < 10, i++, ClearAll[inFoo]; foo[x_] /; ! TrueQ[inFoo] := Block[{inFoo = True}, foo[x] + 1]; Print[foo[2]] ] the output is 3, 4, 4, 4... with the function being updated only once. Is this the behaviour expected? | |
| Mar 22, 2013 at 0:30 | comment | added | Leonid Shifrin | @Stefano Yes, this is exactly what happens. Glad I could help. Thanks for the accept. | |
| Mar 22, 2013 at 0:22 | vote | accept | Stefano | ||
| Mar 22, 2013 at 0:18 | comment | added | Stefano | Thank you very much for the quick answer, which solved the issue. Is it right to say that the trick is able to "freeze" further evaluations of the function because after the first call to foo the flag inFoo is set to True and therefore the condition ! TrueQ[inFoo] necessary to evaluating foo cannot be further met? | |
| Mar 21, 2013 at 16:24 | history | answered | Leonid Shifrin | CC BY-SA 3.0 |