What's the meaning of #0?Confusing efficiency and evaluation when returning pure functions?Split dataset...

Coworker is trying to get me to sign his petition to run for office. How to decline politely?

Build ASCII Podiums

Is it Safe to Plug an Extension Cord Into a Power Strip?

Why does this quiz question say that protons and electrons do not combine to form neutrons?

Can a Hydra make multiple opportunity attacks at once?

How many copper coins fit inside a cubic foot?

Spanning tree Priority values

Draw triangle with text in vertices/edges

What does an unprocessed RAW file look like?

How Create a list of the first 10,000 digits of Pi and sum it?

How can I make my enemies feel real and make combat more engaging?

Why would you use 2 alternate layout buttons instead of 1, when only one can be selected at once

Why Third 'Reich'? Why is 'reich' not translated when 'third' is? What is the English synonym of reich?

How do I handle a blinded enemy which wants to attack someone it's sure is there?

Was the Soviet N1 really capable of sending 9.6 GB/s of telemetry?

What is formjacking?

When distributing a Linux kernel driver as source code, what's the difference between Proprietary and GPL license?

Boss asked me to sign a resignation paper without a date on it along with my new contract

Including proofs of known theorems in master's thesis

How do I write a maintainable, fast, compile-time bit-mask in C++?

Do these large-scale, human power-plant-tending robots from the Matrix movies have a name, in-universe or out?

What's the function of the word "ли" in the following contexts?

Why do we interpret the accelerated expansion of the universe as the proof for the existence of dark energy?

What is an explicit bijection in combinatorics?



What's the meaning of #0?


Confusing efficiency and evaluation when returning pure functions?Split dataset based on the first columnWhat happens when you divide by ##?Using Through with SlotSequence“Nonatomic expression” error when identifying certain positions in a listTranslating syntax of a pure functionSelect with test function that depends on #Defining an operator: Partially evaluate a Pure FunctionMapping over array/matrix the efficient(compact) wayLooking for a better way use multiple pure functions to condense repetitive code













3












$begingroup$


Here's a line of code from a handbook written by Stephen Wolfram, which turns out to be very complicated for me.





If[#1 > 2, 2 #0[#1 - #0[#1 - 2]], 1] & /@ Range[50]





The output is:



{1, 1, 2, 4, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4, 2, 16, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4, 8, 16, 16, 8, 4, 16, 32, 4, 4, 32, 64, 4, 2, 64, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4}


I am confused about the Slot 0(#0) here, or how could I break down the code and understand it?










share|improve this question







New contributor




Shawn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$

















    3












    $begingroup$


    Here's a line of code from a handbook written by Stephen Wolfram, which turns out to be very complicated for me.





    If[#1 > 2, 2 #0[#1 - #0[#1 - 2]], 1] & /@ Range[50]





    The output is:



    {1, 1, 2, 4, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4, 2, 16, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4, 8, 16, 16, 8, 4, 16, 32, 4, 4, 32, 64, 4, 2, 64, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4}


    I am confused about the Slot 0(#0) here, or how could I break down the code and understand it?










    share|improve this question







    New contributor




    Shawn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      3












      3








      3





      $begingroup$


      Here's a line of code from a handbook written by Stephen Wolfram, which turns out to be very complicated for me.





      If[#1 > 2, 2 #0[#1 - #0[#1 - 2]], 1] & /@ Range[50]





      The output is:



      {1, 1, 2, 4, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4, 2, 16, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4, 8, 16, 16, 8, 4, 16, 32, 4, 4, 32, 64, 4, 2, 64, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4}


      I am confused about the Slot 0(#0) here, or how could I break down the code and understand it?










      share|improve this question







      New contributor




      Shawn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      Here's a line of code from a handbook written by Stephen Wolfram, which turns out to be very complicated for me.





      If[#1 > 2, 2 #0[#1 - #0[#1 - 2]], 1] & /@ Range[50]





      The output is:



      {1, 1, 2, 4, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4, 2, 16, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4, 8, 16, 16, 8, 4, 16, 32, 4, 4, 32, 64, 4, 2, 64, 4, 2, 4, 4, 8, 4, 4, 8, 16, 4}


      I am confused about the Slot 0(#0) here, or how could I break down the code and understand it?







      pure-function






      share|improve this question







      New contributor




      Shawn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Shawn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Shawn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 hours ago









      ShawnShawn

      182




      182




      New contributor




      Shawn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Shawn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Shawn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          4












          $begingroup$

          #0 refers to the function itself. This is consistent with the "0th" argument being the head of an expression.



          Example:



          Print[#0] &[]

          (* prints Print[#0]& *)


          In practice, this is useful for writing recursive functions. This is what it is used for in your example. The example could be rephrased as



          f[x_] := If[x > 2, 2 f[x - f[x - 2]], 1]





          share|improve this answer









          $endgroup$













            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',
            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
            });


            }
            });






            Shawn is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f191999%2fwhats-the-meaning-of-0%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4












            $begingroup$

            #0 refers to the function itself. This is consistent with the "0th" argument being the head of an expression.



            Example:



            Print[#0] &[]

            (* prints Print[#0]& *)


            In practice, this is useful for writing recursive functions. This is what it is used for in your example. The example could be rephrased as



            f[x_] := If[x > 2, 2 f[x - f[x - 2]], 1]





            share|improve this answer









            $endgroup$


















              4












              $begingroup$

              #0 refers to the function itself. This is consistent with the "0th" argument being the head of an expression.



              Example:



              Print[#0] &[]

              (* prints Print[#0]& *)


              In practice, this is useful for writing recursive functions. This is what it is used for in your example. The example could be rephrased as



              f[x_] := If[x > 2, 2 f[x - f[x - 2]], 1]





              share|improve this answer









              $endgroup$
















                4












                4








                4





                $begingroup$

                #0 refers to the function itself. This is consistent with the "0th" argument being the head of an expression.



                Example:



                Print[#0] &[]

                (* prints Print[#0]& *)


                In practice, this is useful for writing recursive functions. This is what it is used for in your example. The example could be rephrased as



                f[x_] := If[x > 2, 2 f[x - f[x - 2]], 1]





                share|improve this answer









                $endgroup$



                #0 refers to the function itself. This is consistent with the "0th" argument being the head of an expression.



                Example:



                Print[#0] &[]

                (* prints Print[#0]& *)


                In practice, this is useful for writing recursive functions. This is what it is used for in your example. The example could be rephrased as



                f[x_] := If[x > 2, 2 f[x - f[x - 2]], 1]






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                SzabolcsSzabolcs

                160k14437934




                160k14437934






















                    Shawn is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Shawn is a new contributor. Be nice, and check out our Code of Conduct.













                    Shawn is a new contributor. Be nice, and check out our Code of Conduct.












                    Shawn is a new contributor. Be nice, and check out our Code of Conduct.
















                    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%2f191999%2fwhats-the-meaning-of-0%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

                    Szabolcs (Ungheria) Altri progetti | Menu di navigazione48°10′14.56″N 21°29′33.14″E /...

                    Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

                    How to make inet_server_addr() return localhost in spite of ::1/128RETURN NEXT in Postgres FunctionConnect to...