Tag Info

Hot answers tagged


Your goal is clear, but it contradicts with Mathematica evaluation order. The main problem is that Length evaluates its argument. Please check this question and especially Leonid's comments. You can use my answer with two UpValue definitions from there, but I don't recommend to do so. Clear[returnsList, returnsLength] Length[returnsList[a_]] ^:= ...


I am not sure you are doing anything wrong (i.e., perhaps this is a bug) but a little experimenting shows that your TagSetDelayed expression must be evaluated before returnsList has any down values. That is, the following sequence of evaluations succeeds. Clear[returnsList, returnsLength] returnsList /: Length[returnsList[a_]] := returnsLength[a] ...

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