Maybe this is just my procedural background showing, but is it a good idea to use these recursive functions?

Well, they are examples, and no you probably wouldn't want to actually do a recursive length function (especially since you can just do +@array in perl 6 to get the same thing). But recusion is not the bad thing it used to be back in the days of low CPU/low memory, and even then it was mostly an implementation issue.

In Perl 5 this blows the stack when too many arguments are passed.

Perl 5 actually does not have a stack (at least not in the same way that C has a stack). Perl 5 can recurse forever (or until your memory runs out). See this thead for more details.

I assume this works fine in ML because it is tail-recursive

Actually neither of those ML functions are tail recursive as both of them force all calculation to be done at the last moment. They could both be optimized to be tail recusive though. And ML's efficiency actually does not come from tail recursion, but from a stackless compilation model (IIRC based on heaps) which is specifically made with recursion in mind (sort of the opposite of C's compilation model).

Does this work better in PUGS and the planned Perl 6?

Well PUGS is written in Haskell, which is also a functional language like ML, which handles recursion just fine as well. However, i cannot say if that will actually matter since it matter more how autrijus is writing the interpreter than the language he is using to write it in. However, I assume that recursion will be reasonably efficient in perl 6 (however it is not all that un-efficient in perl 5 though).

-stvn

In reply to Re^2: Functional Perl 6/PUGS by stvn
in thread Functional Perl 6/PUGS 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.