[nem-en] An idea on tail recursible functions
Michal Moskal
michal.moskal at gmail.com
Tue Jul 4 20:32:58 CEST 2006
On 7/4/06, Snaury <snaury at gmail.com> wrote:
> On 7/3/06, Kamil Skalski <kamil.skalski at gmail.com> wrote:
> > Actually getting rid of one / two calls is not very useful.
>
> I don't know. Take, for example, my late macro (download the latest
> version), inside of invoke() it has function make_call() which is
> called twice with different parameters. Because of this it was made
> into static method, *and* now it takes a closure. So creation of
> closure (which is a class with all the runtime junk) with every
> invocation of invoke() is what really bothers me here. If this
> function would not become a static method, there would be no need of
> closure...
Actaully there are some other means of getting rid of closures. One
would be to create a struct instead of a class with the closure (which
takes near-0 time, as it gets allocated on the stack) and pass it
by-ref to the function that needs it. This only works for simple cases
(like the function cannot store the pointer to the closure anywhere),
but still.
Another option would be to pass the arguments directly, instead of
using the closure. This would only work if they are immutable, or if
we pass them by-ref.
It's hard to tell how useful would that be, though.
--
Michał
More information about the devel-en
mailing list