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: [mg75820] Re: [mg75785] infinite loop depending on previous function call
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Fri, 11 May 2007 05:29:39 -0400 (EDT)
  • References: <20158545.1178791721375.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

h always returns a string when given a string, so g[anyString,j] (if j^== 0)  

is g[anotherString,j], so g calls itself forever.

Voila! Infinite recursion.

The subtleties of redefining Greater are secondary; you have to fix g,  
first.

Bobby

On Thu, 10 May 2007 04:21:30 -0500, Hannes Kessler  
<HannesKessler at hushmail.com> 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
>
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Simplify by Recurrence Relations
  • Next by Date: Mathematica 6(66!)
  • Previous by thread: Re: infinite loop depending on previous function call
  • Next by thread: 6.0 not seeing style sheets in $InstallationDirectory/SystemFiles/FrontEnd/StyleSheets