wolfram mathematica - Local variable and Block usage -
i wrote code executes function receives (future) client, in loop parameters. call func(name it).
inside function client generate expression in same variables(by getuncertainty - each variable must cleared before use). , simple idea use block. later , code executed handles di , outside function.so, di , must globals(there more, flexible).
btw, know not efficient, efficiency not issue.
func[v_, a_, r_] := (v = v; = a; r = r; block[{v, a, r},i = v + 10 + r 100; di = getuncertainty[i, {v, a, r}];] ; print[di])
the problem client must reset vars hand. means function parameters can't v_,a_,r_ , otherwise vars in block replace values. didn't manage overcome in other way.
another question in similar issue. if have vars = {v,a,r,dr} , block[vars , ..code.. ] , throws error not list.whereas block[ {v,a,r,dr},..code..] works. how overcome this?
thanks.
its hard unravel trying do, best approach may never assign values symbols need used pure symbols in context. don't need block[].
func[v_, a_, r_] := ( = v + 10 + r 100; di = getuncertainty[i, {v, a, r}]; print[di /. {v->v,a->a,r->r])
starting own symbol names caps frowned upon way risk conflict built in symbols.
note there dedicated site mathematica.stackexchange.com
Comments
Post a Comment