Transferring DownValues

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












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










share|improve this question



















  • 2




    (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
    1 hour ago














up vote
1
down vote

favorite












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










share|improve this question



















  • 2




    (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
    1 hour ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











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










share|improve this question















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







symbolic assignment built-in-symbols






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 48 mins ago









Carl Woll

61.1k280157




61.1k280157










asked 1 hour ago









siderius

365




365







  • 2




    (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
    1 hour ago












  • 2




    (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
    1 hour ago







2




2




(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
1 hour ago




(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
1 hour ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










DownValues[cc] = DownValues[cctemp] /. cctemp -> cc;
cc[1, 9]



87




cc[1, 2]



13




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]]&]





share|improve this answer





























    up vote
    3
    down vote













    You can make use of the undocumented Language`ExtendedDefinition function that underlies the Wolfram Cloud. Suppose:



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


    Then:



    Language`ExtendedDefiniition[cc] = Language`ExtendedDefinition[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







    share|improve this answer




















    • 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
      1 hour ago










    • @siderius There is no package, the function is built-in. Using Language`ExtendedDefinition transfers UpValues, DownValues, FormatValues, etc. If all you care about are DownValues, then using DownValues instead is better.
      – Carl Woll
      55 mins ago










    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184046%2ftransferring-downvalues%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    DownValues[cc] = DownValues[cctemp] /. cctemp -> cc;
    cc[1, 9]



    87




    cc[1, 2]



    13




    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]]&]





    share|improve this answer


























      up vote
      2
      down vote



      accepted










      DownValues[cc] = DownValues[cctemp] /. cctemp -> cc;
      cc[1, 9]



      87




      cc[1, 2]



      13




      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]]&]





      share|improve this answer
























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        DownValues[cc] = DownValues[cctemp] /. cctemp -> cc;
        cc[1, 9]



        87




        cc[1, 2]



        13




        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]]&]





        share|improve this answer














        DownValues[cc] = DownValues[cctemp] /. cctemp -> cc;
        cc[1, 9]



        87




        cc[1, 2]



        13




        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]]&]






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 50 mins ago

























        answered 1 hour ago









        kglr

        166k8188388




        166k8188388




















            up vote
            3
            down vote













            You can make use of the undocumented Language`ExtendedDefinition function that underlies the Wolfram Cloud. Suppose:



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


            Then:



            Language`ExtendedDefiniition[cc] = Language`ExtendedDefinition[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







            share|improve this answer




















            • 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
              1 hour ago










            • @siderius There is no package, the function is built-in. Using Language`ExtendedDefinition transfers UpValues, DownValues, FormatValues, etc. If all you care about are DownValues, then using DownValues instead is better.
              – Carl Woll
              55 mins ago














            up vote
            3
            down vote













            You can make use of the undocumented Language`ExtendedDefinition function that underlies the Wolfram Cloud. Suppose:



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


            Then:



            Language`ExtendedDefiniition[cc] = Language`ExtendedDefinition[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







            share|improve this answer




















            • 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
              1 hour ago










            • @siderius There is no package, the function is built-in. Using Language`ExtendedDefinition transfers UpValues, DownValues, FormatValues, etc. If all you care about are DownValues, then using DownValues instead is better.
              – Carl Woll
              55 mins ago












            up vote
            3
            down vote










            up vote
            3
            down vote









            You can make use of the undocumented Language`ExtendedDefinition function that underlies the Wolfram Cloud. Suppose:



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


            Then:



            Language`ExtendedDefiniition[cc] = Language`ExtendedDefinition[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







            share|improve this answer












            You can make use of the undocumented Language`ExtendedDefinition function that underlies the Wolfram Cloud. Suppose:



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


            Then:



            Language`ExtendedDefiniition[cc] = Language`ExtendedDefinition[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








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 1 hour ago









            Carl Woll

            61.1k280157




            61.1k280157











            • 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
              1 hour ago










            • @siderius There is no package, the function is built-in. Using Language`ExtendedDefinition transfers UpValues, DownValues, FormatValues, etc. If all you care about are DownValues, then using DownValues instead is better.
              – Carl Woll
              55 mins ago
















            • 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
              1 hour ago










            • @siderius There is no package, the function is built-in. Using Language`ExtendedDefinition transfers UpValues, DownValues, FormatValues, etc. If all you care about are DownValues, then using DownValues instead is better.
              – Carl Woll
              55 mins ago















            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
            1 hour ago




            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
            1 hour ago












            @siderius There is no package, the function is built-in. Using Language`ExtendedDefinition transfers UpValues, DownValues, FormatValues, etc. If all you care about are DownValues, then using DownValues instead is better.
            – Carl Woll
            55 mins ago




            @siderius There is no package, the function is built-in. Using Language`ExtendedDefinition transfers UpValues, DownValues, FormatValues, etc. If all you care about are DownValues, then using DownValues instead is better.
            – Carl Woll
            55 mins ago

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184046%2ftransferring-downvalues%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery