MathGroup Archive 2006

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

Search the Archive

Re: Block v. Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68201] Re: Block v. Module
  • From: "Norbert Marxer" <marxer at mec.li>
  • Date: Sat, 29 Jul 2006 01:00:27 -0400 (EDT)
  • References: <eaa23s$nde$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Bruce

The StringReplace command does not work as you expect, because the
local variable x is represented by x$nnn inside Module (you can see
this using Print[x] inside Module). Therefore each character of the
Y-String is replaced by the outside x (i.e. {"yes", "no"}).

Best Regards
Norbert Marxer
www.mec.li


Bruce Colletti wrote:
> Re Mathematica 5.2.0.0.
>
> The Module and Block below "should" return the same result, but they don't.  The Module's result makes no sense, while the Block's result is what I want.
>
> What's Module doing?  The way I read the Help Text, both should return the same result.
>
> Thankx.
>
> Bruce
>
> f[Y_String]:=Module[{x},x=StringReplace[Y,{x_->x}]];
> x={"yes","no"};
> f@"xyz"
>
> {yes,no}~~{yes,no}~~{yes,no}
>
>
> f[Y_String]:=Block[{x},x=StringReplace[Y,{x_->x}]];
> x={"yes","no"};
> f@"xyz"
> 
> Out[3]=
> xyz


  • Prev by Date: RE: Log Function
  • Next by Date: Finding the Number of Pythagorean Triples below a bound
  • Previous by thread: Block v. Module
  • Next by thread: Re: Block v. Module