MathGroup Archive 2000

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

Search the Archive

Using Block instead of Module?


Dear listers,

I try to output results to a file whose name is variable, and find Module 
statement cannot fulfill this purpose, only Block can do. For example,

outputTest[lst_List, id_Integer] := Module[{fname, tmp = lst},
      fname = ToString[id] <> ".txt";
      ToExpression["tmp >>" <> fname];
      ];

outputTest[{1, 2, 3}, 3]

The output file is 3.txt, but the content is "tmp". But if I change 
Module statement into Block as below:

outputTest[lst_List, id_Integer] := Block[{fname, tmp = lst},
      fname = ToString[id] <> ".txt";
      ToExpression["tmp >>" <> fname];
      ];

outputTest[{1, 2, 3}, 3]

The output file is 3.txt, and the content is correct, {1, 2, 3}. How if 
one used to use Module, like me, should do for the same purpose?

Wen-Feng


  • Prev by Date: unexpected Simplify[] ouput
  • Next by Date: Programming+Goto
  • Previous by thread: Re: unexpected Simplify[] ouput
  • Next by thread: Re: Using Block instead of Module?