I'd like to write a function operating on a list, returning a list, but also changing a replacement rule. Let's say I have a list of replacement rules:
data={
...
a->3,
...
};
Now I write a function:
f1[{b_,c_}]:={b+1,c+1};
What I would also like this function to do is to change the replacement rule of data
list, so that after the function is evaluated (with any list as an input), the variable a
would take the value of the evaluated c+1
expression, or f1[[2]]
if You will. Seems like an easy task, but somehow confuses me.
Edit:
As an input I would like a list l={2,3}
, and {3,4}
as an output, and a replacement rule a->3
changed into a->f1[[2]]
.
In general, my problem is that I want another function later on to access a value produced by f1
, but I would like that other function to call this value from external list and not explicitly from f1
.
{1, 2, a -> 3} /. (a -> _) :> b -> 3
? $\endgroup$f1
to work on list other thandata
, let's sayl={2,3}
and to change replacement rule specified indata
as well, if that is what You're asking. In other words, as an output i would like to get{3,4}
and whenever I calla
after the evaluation, I'd like to get 4. $\endgroup$a
. But If you want to change the rule fora
in the replacement list Yves suggestion can be adapted to do what you need: first computef1
, then change the rule list withdata /. Rule[a,_]:>Rule[a,f1[[2]]]
and finally usea /. data
to get the value. If you want to assign a value toa
, why use the replacement list? $\endgroup$