I'm trying to define a function f, such that
f[a_]:=a;
f[f[a__]]:=f[a];
Then, I tried to evaluate f[x,y]. Since f[x,y] satisfies none of these two patterns, it is expected that the result will be just f[x,y]. Nevertheless, in fact, the result is
Hold[f(a,b)]
and I get a error message:
$IterationLimit::itlim: Iteration limit of 4096 exceeded. >>
It seems quite confusing. How could this happen?
Flatattribute. – rcollyer Nov 02 '15 at 14:33?f. Another way to achieve the desired result would bef[Hold@f[a__]]:=f[a];. – Graumagier Nov 02 '15 at 14:40Flatdoes what you want to do. Did you tryf[Hold@f[a__]]:=f[a];? Also take care to clear all definitions/restart the kernel. – Graumagier Nov 02 '15 at 15:24