Re: Assign delayed but fixed value

*To*: mathgroup at smc.vnet.net*Subject*: [mg75211] Re: Assign delayed but fixed value*From*: Albert <awnl at arcor.net>*Date*: Fri, 20 Apr 2007 00:44:39 -0400 (EDT)*References*: <f079pm$47d$1@smc.vnet.net>

zac wrote: > Dear Group! > > My target is to define the value of 'var' in terms of the value of > 'param'. The problem is that 'param' is introduced later than 'var', > and this time-sequence cannot be changed. However, I would like to > create 'var' such a way that IF 'param' is known, the value of 'var' > should be the same any time it is called. > Example code: > > In[1]:= > var = Table[Random[Integer,{0,3}],{param}]; > param = 3; > The following does what I think you try to do. Note that the following code will return the same value for var even if param changes. This is unlikely what you want. var := If[ValueQ[param], var = Table[Random[Integer, {0, 3}], {param}], Indeterminate]; Here is a more elaborate version which behaves more reasonable concerning different values of param: varcache[p_]:=varcache[p]=Table[Random[Integer,{0,3}],{param}]; var := If[ValueQ[param], varcache[param],Indeterminate]; Still I wonder why you don't just use a function which accepts an argument, which would be much clearer code, I think... hth, albert