MethodHandle loop body parameters and Stream.reduce accumulator parameters are not in the same order
Remi Forax
forax at univ-mlv.fr
Wed Sep 14 13:19:41 UTC 2016
Hi everybody,
i've just found that the parameters of the body (a MethodHandle) of MethodHandles.countedLoop (both overloads) and iteratedLoop are not in the same order as the accumulator in methods Stream.reduce, given that they conceptually represent the same thing, i think the first two parameters of body should be swapped in countedLoop and iteratedLoop.
in Stream:
<U> U reduce(U identity,
BiFunction<U,? super T,U> accumulator,
BinaryOperator<U> combiner)
so this is equivalent to value = accumulator(value, element)
In MethodHandles:
MethodHandle iteratedLoop(MethodHandle iterator,
MethodHandle init,
MethodHandle body)
with value = body(element, value, iterable)
it should be
value = body(value, element, iterable).
Same things for
MethodHandle countedLoop(MethodHandle start,
MethodHandle end,
MethodHandle init,
MethodHandle body)
it should be
value = body(value, index, array);
instead of
value = body(index, value, array);
the other loop combinators do not be to be changed.
cheers,
Rémi
More information about the mlvm-dev
mailing list