MathGroup Archive 2000

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

Search the Archive

Re: Using Block instead of Module?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24260] Re: [mg24251] Using Block instead of Module?
  • From: BobHanlon at aol.com
  • Date: Wed, 5 Jul 2000 23:10:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 7/4/2000 3:40:03 PM, d8442803 at student.nsysu.edu.tw writes:

>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?
>

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

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


Bob Hanlon


  • Prev by Date: Plotting multiple functions using Map
  • Next by Date: Re: 1/Trig function - help
  • Previous by thread: Using Block instead of Module?
  • Next by thread: Re: Using Block instead of Module?