in reply to Re: Functional Perl 6/PUGS
in thread Functional Perl 6/PUGS

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