I have been reading alot about Perl's compilation stage (mostly in the Camel book), and looking at various modules that seem to manipulate the op_code tree and other internal aspects of Perl. All this is fascinating to me, as I cannot think of any other language which gives you this much ability to play and/or shoot yourself in the foot.

Being a fan of functional programming (of the LISP, SCHEME & ML varieties), I love the elegance of a recursive algorithm. But being a Perl programmer by trade, I find the inefficiency of recursion to be a problem, and end up having to code the less elegant imperative versions. Which brings me to my question(s).

Has anyone ever tried to implement tail recursion in Perl? Either in the interpreter code itself, or through the manipulation of the op_code tree? Would it even be possible given whats available?

I look at things like Stackless Python and drool at its virtually unlimited recursion and freedom from the C stack. And the ML compilation model (which I only barely understand), but which seems to almost be devoid of a stack entirely and operate on a more heap-ish paradigm.

Oh yeah, and lastly, if anyone can point me to some good resources on manipulating Perl's internals/op_code (preferably from Perl not from C) that would be HIGHLY appreciated.

Happy New Year to all!

-stvn

In reply to Tail Recursion in Perl by stvn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.