break seen as a C archaism
Remi Forax
forax at univ-mlv.fr
Fri Mar 16 09:56:18 UTC 2018
Hi Peter,
I think this have been ruled out but Brian saying that we do not want to add a block that ends with an expression in Java.
And i think we can use parenthesis to avoid to re-interpret what a
int value = do(
int x = foo();
break x * x;
);
If we go in that direction, i think i prefer the comprehension-like syntax where you put the expression giving the result first and then the block that calculates the value,
it has the advantage of being an expression, so it fits with the arrow syntax
switch(value) {
case 0 -> 0
case 1 -> x * x with { x = foo(); }
}
regards,
Rémi
> De: "Peter Levart" <peter.levart at gmail.com>
> À: "John Rose" <john.r.rose at oracle.com>, "Maurizio Cimadamore"
> <maurizio.cimadamore at oracle.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Vendredi 16 Mars 2018 10:39:05
> Objet: Re: break seen as a C archaism
> Expanding on do...
> On 03/16/18 09:50, Peter Levart wrote:
>> And if "while (false)" could be optional, we get:
> Or better yet, make "while (true)" optional even in statement do, so we can
> finally get away with some more boilerplate:
> for (;;) {
> }
> or
> while (true) {
> }
> and simply do:
> do {
> }
> For e-do, the choice of default "while (true)" is fine, because it aligns with
> the fact that there has to be a break <value> somewhere to exit it anyway
> because it has to yield a result. But there will be some danger that a
> programmer codes an infinite loop by mistake.
>> doSomething(
>> par1,
>> do {
>> // compute result...
>> break resut;
>> },
>> par3
>> );
> Expanding on e-do... It could be a building block for e-switch. Remi is
> advocating for expression-only case(s) in e-switch. Combined with e-do, we
> could write:
> int y = switch (x) {
> case 1 -> 2;
> case 2 -> 3;
> case 3 -> do {
> r = ...;
> break r;
> };
> };
> What we loose here is fallthrough. And we still have "break" here too.
> It's unfortunate that we couldn't find a way to have an e-{block} of a kind when
> lambdas have been conceived. That way we could get away with expression-only
> lambdas and expression-only cases in e-switch using the same building block.
> But I guess the statement lambda has its weight with its "return" sticking out
> and reminding us about the scope.
> Regards, Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20180316/75bdf85e/attachment.html>
More information about the amber-spec-experts
mailing list