Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: How am i doing?

by hippo (Archbishop)
on Jul 21, 2025 at 10:38 UTC ( [id://11165737]=note: print w/replies, xml ) Need Help??


in reply to Re^4: How am i doing?
in thread How am i doing?

Yes, you do recall correctly. From section 1.8 of HOP (page 33 in my version):

Sometimes a problem appears to be naturally recursive, and then the recursive solution is grossly inefficient. A very simple example arises when you want to compute Fibonacci numbers. This is a rather unrealistic example, but it has the benefit of being very simple.

🦛

Replies are listed 'Best First'.
Re^6: How am i doing?
by choroba (Cardinal) on Jul 21, 2025 at 11:44 UTC
    > Keep in mind that the classic MIT lectures on programming used to be in Lisp and original Lisp didn't have loops, only those "tail recursions".

    I know pretty well, and that's not just Lisp. At $job-2, we had a significant codebase in Erlang, which doesn't have loops, either.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      IIRC Fibonacci was also heavily used to show the advantages of Haskell in one of the canonical books.

      But unfortunately I never went thru learning Haskell.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

        You can define an (infinite, FSVO infinite limited by your patience and available RAM) list without defining a new function, just summing itself with the rest of itself: fibs = 0 : 1 : zipWith (+) fibs (tail fibs), and then you can get the first however many you need with take. Once realized it won't have to recompute anything again.

        (I did have to crib from a wiki because I couldn't remember if it was just zip or not.)

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

        The nerf ball skirmish rages, "What is an apposite non-pedagogical example of recursion?" the casus belli; then, a pause: From a foxhole betwixt comes a plaintive query, "How about Quicksort?"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11165737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2026-04-10 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.