Hello Kuba, very interesting, perfect explanation, many thanks!
Best regards -- Henrik
Dear Sander, Neil, Hans,
many thanks for looking into that problem! Using SetDelayed was my first guess too. @Hans Milton: Yes, I had found that out already, thank you, and this is probably the way to go. But I basically would like to understand, why my approach above is not working ...
SetDelayed
In[1]:= func[arg_ /; validQ] := arg foo[a_] := func[a] In[3]:= validQ = False; foo[p] Out[4]= func[p] In[5]:= validQ = True; foo[p] Out[6]= p
Oops, I guess I should have tried it first!
Henrik,
The problem is because of Set[] (=) vs SetDelayed[] (:=)
When you defined foo with =, validQ was false. If you define foo with := it will use the value of validQ at evaluation time, not at define time.
I hope this helps,
Neil
I tried that, changing all to SetDelayed, but also didn't work for me
Interesting question for which I have no answer unfortunately, but I hope to find out by leaving a message here