[External] : Re: Rehabilitating switch -- a scorecard

forax at univ-mlv.fr forax at univ-mlv.fr
Wed May 19 10:43:20 UTC 2021

----- Mail original -----
> De: "Guy Steele" <guy.steele at oracle.com>
> À: "Brian Goetz" <brian.goetz at oracle.com>
> Cc: "Remi Forax" <forax at univ-mlv.fr>, "John Rose" <john.r.rose at oracle.com>, "amber-spec-experts"
> <amber-spec-experts at openjdk.java.net>
> Envoyé: Mardi 18 Mai 2021 21:33:45
> Objet: Re: [External] : Re: Rehabilitating switch -- a scorecard

>> On May 18, 2021, at 2:19 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>>>>>   - tuple as first class citizen
>>>> Sorry, no.  I know you really want this, but this is similar to the
>>>> function-type-vs-functional-interface issue.  We made our choice when we
>>>> did records -- records are our tuples.
>>> I'm hunting around deconstructor and methods that returns several values.
>> I know that, and I'm telling you these are not the droids you are looking for.
> If only we had tail calls. Then instead of writing
> (int q, int r) = quotientAndRemainder(m, n);
> whatever
> we could write (using my preferred syntax for a mandatory tail call in Java)
> goto quotientAndRemainder(m, n, (int q, int r) -> whatever);
> (the method quotientAndRemainder would of course tail-call its third argument),
> with no need of tuples or even records to get multiple values out of a method,
> and then everyone would be happy, right?  RIGHT?  :-) :-/ :-P
> —Guy

This remember me something, tail call optimization is not the only optimization that avoid the stack to grow.

If you have calls like
  g(a, () -> h(a, () -> f(a)))

with 'a' being the same arguments, you can transform them to
  r1 = f(a)
  r2 = h(a, () -> r1)
  r3 = g(a, () -> r2)

Here the calls can be at any location in the method, but the argument should not depend on the values computed by the function.

The interceptors of Spring or CDI exhibit calls like this, they are using the same arguments so the result do not depend on the order of which the functions/interceptors are executed,
but as far as i know, there is not implementation that do that transformation so when an exception occurs we see long stack traces.
Asking for a friend, is this transformation have already a name ?


More information about the amber-spec-experts mailing list