Module/Block problem (passing pointers?)
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1847] Module/Block problem (passing pointers?)
- From: sherod at boussinesq.Colorado.EDU (Scott Herod)
- Date: Mon, 7 Aug 1995 20:26:23 -0400
- Organization: University of Colorado at Boulder
I've got a problem that seems to call for using the Block construct over a Module, but for other reasons, I Modules are more appropriate. I'll show the set-up with a Block and ask how I can make it a module. Here is the basic code. test1 := Block[{flag}, Print["1,1 ",flag]; test2; Print["1,2 ",flag]; ] test2 := Module[{}, Print["2,1 ",flag]; flag = True; Print["2,2 ", flag]; ] In[3]:= test1 1,1 flag 2,1 flag 2,2 True 1,2 True This does what I want, ie "flag" is a local variable to the test1's execution and test1 knows that the value of flag was set in test2. I would really like test1 to be defined in terms of a Module, not a Block. Any suggestions? Oh, in the real problem, test2 is already a function and it would be inelegant to have it return flag as well. If it were possible to pass pointers it would be easy to send test2 the flag pointer and then check it in test1. But I believe that Mathematica can only pass values, correct? Scott Herod Applied Mathematics University of Colorado, Boulder sherod at newton.colorado.edu