changing number of arguments to a function in secondary evaluationusing a Mathematica function to define a...

Ordering a word list

During the Space Shuttle Columbia Disaster of 2003, Why Did The Flight Director Say, "Lock the doors."?

Unique combinations of a list of tuples

Look mom! I made my own (Base 10) numeral system!

Dropdowns & Chevrons for Right to Left languages

How can you evade tax by getting employment income just in equity, then using this equity as collateral to take out loan?

Double blind peer review when paper cites author's GitHub repo for code

Ex-contractor published company source code and secrets online

Blocking people from taking pictures of me with smartphone

Are there any financial disadvantages to living significantly "below your means"?

Can a spacecraft use an accelerometer to determine its orientation?

In reversi, can you overwrite two chips in one move?

Accidentals - some in brackets, some not

Does a code snippet compile? Or does it get compiled?

Is refreshing multiple times a test case for web applications?

As a 16 year old, how can I keep my money safe from my mother?

Can I call myself an assistant professor without a PhD?

What are the uses and limitations of Persuasion, Insight, and Deception against other PCs?

Why isn’t SHA-3 in wider use?

How to mark beverage cans in a cooler for a blind person?

How quickly could a country build a tall concrete wall around a city?

Could one become a successful researcher by writing some really good papers while being outside academia?

Are there any differences in causality between linear and logistic regression?

How can I tell if a flight itinerary is fake?



changing number of arguments to a function in secondary evaluation


using a Mathematica function to define a new functionConstruct a function whose definition depends on the values of its arguments and evaluates a SectionHow to get the parameter number of inbuilt functionHow to hold evaluation of a value that is passed to a functionFormatting Display PrecisionUsing DeleteCases with a defined function with two arguments as a patternFunctions that remember some arguments while not remembering other arguments






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







5












$begingroup$


So I have a function that produces answers involving uninstantiated(?) function names, e.g.



 Out[1]= f[a,b,c,d].


I then want to evalute this leftover result by, say, replacing this f[a,b,c,d] with a defined function g[a,b,c,d,e].



I think something maybe to do with slots, but my poor attempts have still failed, eg.



 Out[1] /. f[##] &@g[##,e]

Out[1] /. f[___] -> g

Out[1] /. f[#1, #2, #3, #4] -> g[#1, #2, #3, #4, e]









share|improve this question









$endgroup$










  • 2




    $begingroup$
    You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second. E.g. f[a, b, c, d] /. f[x__] :> g[x, e].
    $endgroup$
    – eyorble
    9 hours ago












  • $begingroup$
    Aargh. This comment is an answer! I'll accept it if you want
    $endgroup$
    – nate
    9 hours ago


















5












$begingroup$


So I have a function that produces answers involving uninstantiated(?) function names, e.g.



 Out[1]= f[a,b,c,d].


I then want to evalute this leftover result by, say, replacing this f[a,b,c,d] with a defined function g[a,b,c,d,e].



I think something maybe to do with slots, but my poor attempts have still failed, eg.



 Out[1] /. f[##] &@g[##,e]

Out[1] /. f[___] -> g

Out[1] /. f[#1, #2, #3, #4] -> g[#1, #2, #3, #4, e]









share|improve this question









$endgroup$










  • 2




    $begingroup$
    You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second. E.g. f[a, b, c, d] /. f[x__] :> g[x, e].
    $endgroup$
    – eyorble
    9 hours ago












  • $begingroup$
    Aargh. This comment is an answer! I'll accept it if you want
    $endgroup$
    – nate
    9 hours ago














5












5








5





$begingroup$


So I have a function that produces answers involving uninstantiated(?) function names, e.g.



 Out[1]= f[a,b,c,d].


I then want to evalute this leftover result by, say, replacing this f[a,b,c,d] with a defined function g[a,b,c,d,e].



I think something maybe to do with slots, but my poor attempts have still failed, eg.



 Out[1] /. f[##] &@g[##,e]

Out[1] /. f[___] -> g

Out[1] /. f[#1, #2, #3, #4] -> g[#1, #2, #3, #4, e]









share|improve this question









$endgroup$




So I have a function that produces answers involving uninstantiated(?) function names, e.g.



 Out[1]= f[a,b,c,d].


I then want to evalute this leftover result by, say, replacing this f[a,b,c,d] with a defined function g[a,b,c,d,e].



I think something maybe to do with slots, but my poor attempts have still failed, eg.



 Out[1] /. f[##] &@g[##,e]

Out[1] /. f[___] -> g

Out[1] /. f[#1, #2, #3, #4] -> g[#1, #2, #3, #4, e]






functions argument-patterns






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 9 hours ago









natenate

2751 silver badge7 bronze badges




2751 silver badge7 bronze badges











  • 2




    $begingroup$
    You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second. E.g. f[a, b, c, d] /. f[x__] :> g[x, e].
    $endgroup$
    – eyorble
    9 hours ago












  • $begingroup$
    Aargh. This comment is an answer! I'll accept it if you want
    $endgroup$
    – nate
    9 hours ago














  • 2




    $begingroup$
    You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second. E.g. f[a, b, c, d] /. f[x__] :> g[x, e].
    $endgroup$
    – eyorble
    9 hours ago












  • $begingroup$
    Aargh. This comment is an answer! I'll accept it if you want
    $endgroup$
    – nate
    9 hours ago








2




2




$begingroup$
You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second. E.g. f[a, b, c, d] /. f[x__] :> g[x, e].
$endgroup$
– eyorble
9 hours ago






$begingroup$
You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second. E.g. f[a, b, c, d] /. f[x__] :> g[x, e].
$endgroup$
– eyorble
9 hours ago














$begingroup$
Aargh. This comment is an answer! I'll accept it if you want
$endgroup$
– nate
9 hours ago




$begingroup$
Aargh. This comment is an answer! I'll accept it if you want
$endgroup$
– nate
9 hours ago










2 Answers
2






active

oldest

votes


















6












$begingroup$

From my own comment:



You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second.



For this problem:



f[a, b, c, d] /. f[x__] :> g[x, e]



g[a, b, c, d, e]




Note the use of __, which is two underscores: This is a pattern which grabs 1 or more elements (see also ___ which grabs 0 or more elements), and inserts them as a Sequence when used in replacement. Thus, it doesn't get inserted as a List.



If you wanted to do this with pure functions, it becomes a bit more complicated:



g[Sequence @@ #, e] &[f[a, b, c, d]]



g[a, b, c, d, e]




But note that this isn't dependent on its argument being in the form of f[...], it will replace any functional head. To avoid that requires conditionals of some variety, e.g:



If[Head[#] === f, g[Sequence @@ #, e], Undefined] &[f[a, b, c, d]]





share|improve this answer











$endgroup$























    5












    $begingroup$

    You can also use Apply:



    g[##, e] & @@ f[a, b, c, d]



    g[a, b, c, d, e]




    or ReplaceAll with replacement rule f -> (g[##, e] &):



    f[a, b, c, d] /.  f -> (g[##, e] &)



    g[a, b, c, d, e]







    share|improve this answer









    $endgroup$


















      Your Answer








      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      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%2f203569%2fchanging-number-of-arguments-to-a-function-in-secondary-evaluation%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      6












      $begingroup$

      From my own comment:



      You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second.



      For this problem:



      f[a, b, c, d] /. f[x__] :> g[x, e]



      g[a, b, c, d, e]




      Note the use of __, which is two underscores: This is a pattern which grabs 1 or more elements (see also ___ which grabs 0 or more elements), and inserts them as a Sequence when used in replacement. Thus, it doesn't get inserted as a List.



      If you wanted to do this with pure functions, it becomes a bit more complicated:



      g[Sequence @@ #, e] &[f[a, b, c, d]]



      g[a, b, c, d, e]




      But note that this isn't dependent on its argument being in the form of f[...], it will replace any functional head. To avoid that requires conditionals of some variety, e.g:



      If[Head[#] === f, g[Sequence @@ #, e], Undefined] &[f[a, b, c, d]]





      share|improve this answer











      $endgroup$




















        6












        $begingroup$

        From my own comment:



        You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second.



        For this problem:



        f[a, b, c, d] /. f[x__] :> g[x, e]



        g[a, b, c, d, e]




        Note the use of __, which is two underscores: This is a pattern which grabs 1 or more elements (see also ___ which grabs 0 or more elements), and inserts them as a Sequence when used in replacement. Thus, it doesn't get inserted as a List.



        If you wanted to do this with pure functions, it becomes a bit more complicated:



        g[Sequence @@ #, e] &[f[a, b, c, d]]



        g[a, b, c, d, e]




        But note that this isn't dependent on its argument being in the form of f[...], it will replace any functional head. To avoid that requires conditionals of some variety, e.g:



        If[Head[#] === f, g[Sequence @@ #, e], Undefined] &[f[a, b, c, d]]





        share|improve this answer











        $endgroup$


















          6












          6








          6





          $begingroup$

          From my own comment:



          You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second.



          For this problem:



          f[a, b, c, d] /. f[x__] :> g[x, e]



          g[a, b, c, d, e]




          Note the use of __, which is two underscores: This is a pattern which grabs 1 or more elements (see also ___ which grabs 0 or more elements), and inserts them as a Sequence when used in replacement. Thus, it doesn't get inserted as a List.



          If you wanted to do this with pure functions, it becomes a bit more complicated:



          g[Sequence @@ #, e] &[f[a, b, c, d]]



          g[a, b, c, d, e]




          But note that this isn't dependent on its argument being in the form of f[...], it will replace any functional head. To avoid that requires conditionals of some variety, e.g:



          If[Head[#] === f, g[Sequence @@ #, e], Undefined] &[f[a, b, c, d]]





          share|improve this answer











          $endgroup$



          From my own comment:



          You're mixing the concepts of pure functions (# and &) with replacement (/., ->, :>). Use slots with the first one, use patterns (Pattern in the documentation, x_ or x__ for example in usage) with the second.



          For this problem:



          f[a, b, c, d] /. f[x__] :> g[x, e]



          g[a, b, c, d, e]




          Note the use of __, which is two underscores: This is a pattern which grabs 1 or more elements (see also ___ which grabs 0 or more elements), and inserts them as a Sequence when used in replacement. Thus, it doesn't get inserted as a List.



          If you wanted to do this with pure functions, it becomes a bit more complicated:



          g[Sequence @@ #, e] &[f[a, b, c, d]]



          g[a, b, c, d, e]




          But note that this isn't dependent on its argument being in the form of f[...], it will replace any functional head. To avoid that requires conditionals of some variety, e.g:



          If[Head[#] === f, g[Sequence @@ #, e], Undefined] &[f[a, b, c, d]]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 9 hours ago

























          answered 9 hours ago









          eyorbleeyorble

          6,4931 gold badge11 silver badges30 bronze badges




          6,4931 gold badge11 silver badges30 bronze badges




























              5












              $begingroup$

              You can also use Apply:



              g[##, e] & @@ f[a, b, c, d]



              g[a, b, c, d, e]




              or ReplaceAll with replacement rule f -> (g[##, e] &):



              f[a, b, c, d] /.  f -> (g[##, e] &)



              g[a, b, c, d, e]







              share|improve this answer









              $endgroup$




















                5












                $begingroup$

                You can also use Apply:



                g[##, e] & @@ f[a, b, c, d]



                g[a, b, c, d, e]




                or ReplaceAll with replacement rule f -> (g[##, e] &):



                f[a, b, c, d] /.  f -> (g[##, e] &)



                g[a, b, c, d, e]







                share|improve this answer









                $endgroup$


















                  5












                  5








                  5





                  $begingroup$

                  You can also use Apply:



                  g[##, e] & @@ f[a, b, c, d]



                  g[a, b, c, d, e]




                  or ReplaceAll with replacement rule f -> (g[##, e] &):



                  f[a, b, c, d] /.  f -> (g[##, e] &)



                  g[a, b, c, d, e]







                  share|improve this answer









                  $endgroup$



                  You can also use Apply:



                  g[##, e] & @@ f[a, b, c, d]



                  g[a, b, c, d, e]




                  or ReplaceAll with replacement rule f -> (g[##, e] &):



                  f[a, b, c, d] /.  f -> (g[##, e] &)



                  g[a, b, c, d, e]








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 8 hours ago









                  kglrkglr

                  210k10 gold badges241 silver badges480 bronze badges




                  210k10 gold badges241 silver badges480 bronze badges

































                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Mathematica Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f203569%2fchanging-number-of-arguments-to-a-function-in-secondary-evaluation%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                      Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                      Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...