Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: infinite loop depending on previous function call

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75815] Re: infinite loop depending on previous function call
  • From: dh <dh at metrohm.ch>
  • Date: Fri, 11 May 2007 05:26:57 -0400 (EDT)
  • References: <f1up37$8bl$1@smc.vnet.net>


Hi Hannes,

consider:

g[s_String, y_] := g[h@s, y];

as h will always return a string and y does not change, this will create 

an infinit recursion if y != 0. Probably you wanted to decrease y?

hope this helps, Daniel



Hannes Kessler wrote:

> 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

> 

> 




  • Prev by Date: Re: Can anyone help me Thanks
  • Next by Date: Re: Re: Can one retain ver 5.1 if downloading ver 6.0?
  • Previous by thread: infinite loop depending on previous function call
  • Next by thread: Re: infinite loop depending on previous function call