Re: Module/Block problem (passing pointers?)
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1854] Re: Module/Block problem (passing pointers?)
- From: maeder at inf.ethz.ch (Roman Maeder)
- Date: Mon, 7 Aug 1995 20:27:37 -0400
- Organization: Theoretical Computer Science, ETH Zurich
> 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?
Not correct. The paradigm of in-out (or VAR, or reference) parameters
can be implemented like this (see "The Mathematica Programmer", APP, 1994,
Chapter 1):
SetAttributes[test2, HoldFirst]
test2[s_Symbol] := (
s = True;
)
In[3]:= f = False;
In[4]:= test2[f]
In[5]:= f
Out[5]= True
Now you can do:
test1 := Module[{flag},
Print["1,1 ",flag];
test2[flag];
Print["1,2 ",flag];
]
Roman Maeder