# Transferring DownValues

I have a code in which I define something like this:

cc[1, 2] = 1;
cc[2, 6] = 12;
cc[3, 7] = 3;


After some manipulation I define a sort of temporary variable related to cc:

cctemp[1, 2] = 13;
cctemp[2, 6] = 8;
cctemp[3, 7] = 4;
cctemp[1, 9] = 87;


There are new and old indices.

Now in my code i wanna replace cc with cctemp. I can do the trivial assignment and i can use a Do for the substitution but its not the best. How could I realize the assignment ?

(Ps maybe something like Activate @ Inactive ....)

Thank you

• (1) List is in the title, but it looks like you are assigning DownValues rather than making cc a list. Do you mean cc[[1, 2]] rather than cc[1, 2], etc.? (2) Why can't you just do cc[1, 2] = cctemp[1, 2] (or cc[[1,2]] = cctemp[[1, 2]]? – march Oct 16 '18 at 21:06

DownValues[cc] = DownValues[cctemp] /. cctemp -> cc;

cc @@@ {{1, 2}, {2, 6}, {3, 7}, {1, 9}}


{13, 8, 4, 87}

If cc has some assignments that are not overridden by the assignments in cctemp you can use

DownValues[cc] =  DeleteDuplicatesBy[
Join[DownValues[cctemp], DownValues[cc]] /. cctemp -> cc, #[[1,1]]&]


You can make use of the undocumented LanguageExtendedDefinition function that underlies the Wolfram Cloud. Suppose:

cctemp[1,2] = 13;
cctemp[2,6] = 8;
cctemp[3,7] = 4;
cctemp[1,9] = 87;


Then:

LanguageExtendedDefinition[cc] = LanguageExtendedDefinition[cctemp] /. cctemp -> cc;


Finally:

DownValues[cc]


{HoldPattern[cc[1, 2]] :> 13, HoldPattern[cc[1, 9]] :> 87, HoldPattern[cc[2, 6]] :> 8, HoldPattern[cc[3, 7]] :> 4}

• ok thank you for the answer; just two things because i want to learn: 1) where can i find the package of this function 2) why should i prefer this way over the answer of kglr ? – siderius Oct 16 '18 at 21:17
• @siderius There is no package, the function is built-in. Using LanguageExtendedDefinition transfers UpValues, DownValues, FormatValues, etc. If all you care about are DownValues, then using DownValues instead is better. – Carl Woll Oct 16 '18 at 21:29