Hot answers tagged

16

Others have argued in the comments that this behaviour makes sense mathematically, and I fully agree. But further than that, it is also very practical. Mathematica's functions are usually designed to give reasonable results for edge cases in the sense that if you put these functions together and write some more complex calculation, this compound function ...


3

f[x] === HoldForm[f[x]] does not provide the desired result, because HoldForm stays attached to f[x] on the right side of the expression. Thus, the left and right sides never are identical. Instead use, f[x] === Unevaluated[f[x]] (* True *) And, when the function does something, g[x_] := x^2 g[x] === Unevaluated[g[x]] (* False *) Unevaluated prevents ...


2

tl;dr Use this modified valueQ function. SetAttributes[valueQ, {HoldFirst}]; valueQ[h_[args__]] := With[{eval = args}, ! Hold[Evaluate[h[eval]]] === Hold[h[eval]] ]; How ValueQ works. I learned from @halirutan's answer in ValueQ returns false positive for one argument type only that ValueQ simply tests whether an expression is equal to ...



Only top voted, non community-wiki answers of a minimum length are eligible