infinite loop depending on previous function call
- To: mathgroup at smc.vnet.net
- Subject: [mg75785] infinite loop depending on previous function call
- From: Hannes Kessler <HannesKessler at hushmail.com>
- Date: Thu, 10 May 2007 05:21:30 -0400 (EDT)
Hello, here are 2 string replacement functions: (*1*) k[s_String] := StringReplace[s, {"ab" :> "bb", "a" ~~ EndOfString :> "b"}] (*2*) h[s_String] := FixedPoint[k, s]; Examples: (*e1*) k["aaa"] --> "aab" (*e2*) h["aaa"] --> "bbb" Next, I have some function definitions built on h: (*3*) g[s_String, 0] := 0; (*4*) g[s_String, y_] := g[h@s, y]; (*5*) f[s_String, 0] := True; (*6*) f[s_String, x_] := NumericQ@g[s, x]; NumericQ can be replaced by any other function of a number which returns True or False. And finally, I want to define a generalized inequality ("s0" is a string parameter): (*7*) Unprotect[Greater]; (*8*) Greater[x_ /; f["s0",x], y_ /; f["s0", y]] := Greater[g["s0", x], g["s0", y]]; (*9*) Protect[Greater]; Running (*1*) - (*9) in a fresh kernel including the function call (*e2*) does not cause problems if the function call occurs before the inequality definition (*8*). On the other hand, running (*e2*) the first time only after (*8*) results in an infinite loop without any messages. Can anybody explain this behavior and devise a solution? Thanks in advance. Best regards, Hannes Kessler