MathGroup Archive 2000

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

Search the Archive

Using Block instead of Module?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24251] Using Block instead of Module?
  • From: d8442803 at student.nsysu.edu.tw (Wen-Feng Hsiao)
  • Date: Tue, 4 Jul 2000 15:22:12 -0400 (EDT)
  • Organization: NSYSU
  • Sender: owner-wri-mathgroup at wolfram.com

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?