| Ulrich Hobelmann 2005-11-04, 7:58 am |
| Marcin 'Qrczak' Kowalczyk wrote:
> Ulrich Hobelmann <u.hobelmann@web.de> writes:
>
>
> The point is, what would the macro expand to? It must either pack the
> loop body in a closure and pass it to a different function depending
> on the sequence type, or pack the iterator in an object and perform an
> indirect call for obtaining each element, or jump between the iteration
> and the loop body through continuations.
No, each iteration is only a goto. To find out the sequence type, the
macro could start with checking the sequence type and then do one of
maybe three different loop bodies, or it could use virtual sequence
accessors (is-last-element?, next) with the associated cost, of course.
IMO the programmer should declare the sequence type, though, for
clarity, so in that case you end up with just one fine compiled loop.
> In each case the cost is similar, and there is no gain from iteration
> being a macro except that some people might find the macro syntax nicer.
No, one version doesn't compile anything. The loop has to call the
lambda function on every iteration. The macro version however, creates
a loop to compile, with the iteration body inline. So the only jump is
the test-and-jump-back in the loop. Everything else is code that's
directly executed.
> A lightweight syntax for lambdas means that more control structures
> can be implemented with regular functions instead of with macros.
Yes, but still not enough for my taste ;)
--
The road to hell is paved with good intentions.
|