Akshay Srinivasan <akshaysrinivasan@...> writes:
> Does reduce have a compiler macro ?
> Doing this in SBCL tells me that:
> $ (compiler-macro-function 'reduce)
> but so does this
> $ (compiler-macro-function 'sort)
> However, I've found that optimizations and type declarations in the
> environment do have a significant effect on runtimes of sort. I'm not
> sure how this can be done without compiler macros.
> reduce tends to run quite slow(compared with loop) even with
> type-declarations, and optimize declarations. This does not actually
> bother me much, I'm just curious.
SBCL has more powerful ways of optimizations, e.g., transforms. In the
case of SORT it's declared inline, which allows to eliminate
type-dispatch and apply other optimizations.
reduce may be slow when using functions with arbitrary number of
arguments, e.g. +.
(reduce (lambda (x y) (+ x y)) sequence) would be faster.
But indeed, LOOP in this case becomes more readable and faster.
With best regards, Stas.