[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Addition of map() and filter().
- From: Kristofer Karlsson <kristofer.karlsson@...>
- Date: Wed, 14 Oct 2009 08:45:57 +0200
On Wed, Oct 14, 2009 at 1:08 AM, Mark Hamburg <firstname.lastname@example.org>
This can't be a tail call because it has to process the results of F() to combine them with something before returning further up the chain.
On Oct 13, 2009, at 3:35 PM, TNHarris wrote:
Which could be optimized to use local variables only. However, that does
demonstrate one thing about Lua that I didn't expect. This...
return something, F()
... isn't a tail-call. I thought it would be, but the comma operator is
enough to prevent the optimization. I think it would be a worthwhile
change to the VM to allow a tail-call in this case.
So, in this case, you might actually want to fear recursion.
Basically, you want to write map and filter in C because it will be much easier to work with varargs efficiently in C.
Well, you _could_ make this a special case that supported tail recursion, by offsetting the stack for each prepended argument:
return a, foo() or return a, b, foo(), et.c.
The cases that can't be tail called is stuff like: return 1 + foo()