I'm confused. I'm not sure what this example is supposed to show.
The pattern Plus[b_Foo] evaluates to the pattern b_Foo. So the rule is b_Foo := b. Which infinite loops, obviously.
So I think there are two misunderstandings here: 1) Mathematica doesn't stop evaluating at a FixedPoint. It keeps evaluating until no rules match. So kj is mistaken in expecting it to stop. 2) If you don't want the pattern to evaluate, you need to use HoldPattern. E.g., Foo /: HoldPattern[Plus][b_Foo] := b This doesn't infinite loop, of course, but then again, nothing will match it, because Plus[Foo[x]] will be evaluated away before the rule is ever applied.
So, again, I'm not sure what this example is supposed to show. What exactly is the problem here?
Begin forwarded message:
> From: kj <firstname.lastname@example.org> > Date: December 7, 2010 3:46:27 AM PST > To: email@example.com > Subject: Foo /: Plus[b_Foo] := b > > An innocent-looking upvalue for a brand new symbol Foo: > > In:= Foo /: Plus[b_Foo] := b; > > > Nothing shocking about this rule: it just recapitulates the default > behavior of Plus when given a single argument. And it seems to > work: > > In:= Plus[Foo] > Out= Foo > > > ...but disaster lurks just around the corner: > > In:= 1 + Foo > During evaluation of In:= $IterationLimit::itlim: Iteration limit > of 4096 exceeded. >> > Out= Hold[1 + Foo] > > > I was expecting that 1 + Foo would evaluate to itself, not an > infinite loop.... So I examined a trace: > > In:= ToString[ > StringForm["``", > FullForm /@ Take[Quiet[Trace[1 + Foo]], 10] // ColumnForm]] > > Out= "HoldForm[Plus[1, Foo]] > HoldForm[Plus[1, Foo]] > HoldForm[Plus[1, Foo]] > HoldForm[Plus[1, Foo]] > HoldForm[Plus[1, Foo]] > HoldForm[Plus[1, Foo]] > HoldForm[Plus[1, Foo]] > HoldForm[Plus[1, Foo]] > HoldForm[Plus[1, Foo]] > HoldForm[Plus[1, Foo]]" > > > > > Judging from the trace, the evaluator is attempting to evaluate > the same expression over and over. The evaluator is supposed to > stop when it reaches a fixed point, and that looks like a fixed > point if I ever saw one. (In fact, in this case, we started at > the fixed point to begin with!) So either there's a very serious > bug in the evaluator, or the documentation I read on the subject > was wrong about how it's supposed to work. (FWIW, this is Mathematica > 7.) > > > Whatever it is that I'm doing wrong, it seems to me *very > fundamental*. > IOW, this does not look to me like some obscure corner case. If > so, I can't understand how I could have missed it in all the reading > I've done about Mathematica over the years. It's occurrences like > this that fuel my *paranoia* about the Mathematica documentation. > > If someone can tell me 1) what I'm doing wrong above, and hopefully > 2) how to fix it, I'd much appreciate it. Also, if you could point > me to where in the documentation I would have learned the answers > to these questions I'd be grateful. > > TIA! > > ~kj > > >