1
$\begingroup$

I found some bizarre phenomena in my code. While I'm using Module in my function, the result is incompatible with which I did outside Module, and when I replaced Module with Block it went back to normal. I don't know why.

Edit:

Now the problem becomes this:

Module[{a,b},
a=Sin[x];
b[x_]=a;
b[y]
]

doesn't give Sin[y], while Block gives Sin[y].

$\endgroup$

marked as duplicate by Kuba Apr 21 '17 at 11:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ @Kuba I have found the problem. It seems that my attmption ϕ[x_] = ϕx to make ϕ a pure function failed, so all the following ϕs are function of x. When I change to Block, it seems fine again. Can you help me up with this? $\endgroup$ – Turgon Apr 21 '17 at 10:36
  • $\begingroup$ Many thanks for the edit. Now it is clear you should read this: Enforcing correct variable bindings and avoiding renamings for conflicting variables in nested scoping constructs or just use the solution - Set @@ {b[x_], a} $\endgroup$ – Kuba Apr 21 '17 at 11:01
  • $\begingroup$ @Kuba Thanks a lot. That solved my problem. And really sorry about the inconvenience I brought earlier. $\endgroup$ – Turgon Apr 21 '17 at 11:10
  • $\begingroup$ No worries, it happens, what doesn't happen so often is what you did with the edit so thanks. $\endgroup$ – Kuba Apr 21 '17 at 11:12

Browse other questions tagged or ask your own question.