MathGroup Archive 2009

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

Search the Archive

weird escaping problem with StringPattern inside Module[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100799] weird escaping problem with StringPattern inside Module[]
  • From: divisor <congruentialuminaire at yahoo.com>
  • Date: Sun, 14 Jun 2009 05:40:40 -0400 (EDT)

Hello MathGroup:

I am having a strange problem where my code works fine in a Notebook
session but acts strangely inside a Module[]. I presume that this is
some scoping problem that is currently beyond me.

I know how Module[] takes local variables and adds "$nnn" or something
to the variable. It is doing a similar thing to my string pattern and
I have no idea how to "escape" this and disable this behavior.

Any help you can provide is greatly appreciated.

This code works as expected:

parseVars = {abc, def};
text0 = "the rain in spain stays mainly...";
parsePattern = "the " ~~ abc__ ~~ " in " ~~ def__ ~~ " stays main" ->
parseVars;
Flatten@StringCases[text0, parsePattern]
> {"rain", "spain"}
Print["patt=", parsePattern]
> patt=the ~~abc__~~ in ~~def__~~ stays main->{abc,def}


This is the module containing the exact same logic:

getWeather[inputStr_String] := Module[
  {parseVars, parsePattern}
  , parseVars = {abc, def};
  parsePattern = "the " ~~ abc__ ~~ " in " ~~ def__ ~~ " stays main" -
> parseVars;
  Print["patt=", parsePattern];
  Flatten@StringCases[inputStr, parsePattern]
  ]

This shows the symptom. Notice how the pattern vars are suffixed and
hence do not match those in the rhs of StringCases[] with the result
being all are "no match"!?!?!

getWeather[text0]
> patt=the ~~abc$__~~ in ~~def$__~~ stays main->{abc,def}
> {abc, def}

TIA.

Regards..

Roger Williams
Franklin Laboratory


  • Prev by Date: Re: Inverse / Laplace Transform Halved
  • Next by Date: Re: ParallelTable[ ]
  • Previous by thread: Re: Extracting contour values from ContourPlot
  • Next by thread: Re: weird escaping problem with StringPattern inside Module[]