rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

proposal syntax else ... then for else keyword in conditional branches

Open lyrachord opened this issue 2 years ago • 10 comments

examples in tutorial

if a == b then
  env.out.print("they are the same")
else
  if a > b then
    env.out.print("a is bigger")
  else
    env.out.print("b bigger")
  end
end

limited by set pattern in old school

if a == b then
  env.out.print("they are the same")
elseif a > b then
  env.out.print("a is bigger")
else
  env.out.print("b bigger")
end

just use "else ... then" instead of "elseif ... then"

if a == b then
  env.out.print("they are the same")
else a > b then
  env.out.print("a is bigger")
else
  env.out.print("b bigger")
end

And it is ok in expressions

x = 1 + if lots then 100 else afew then 10 else 2 end

And there is almost no additional cost for parsing.

lyrachord avatar Dec 14 '22 04:12 lyrachord

Without heavy justification in an RFC, I would be against this proposal. I would advise anyone writing an RFC for this to spend a good deal of time explaining why this is better than what currently exists as this adds nothing semantically that isn't already in the language.

SeanTAllen avatar Dec 14 '22 04:12 SeanTAllen

What's the value/improvement that this would bring?

jemc avatar Dec 14 '22 06:12 jemc

What's the value/improvement that this would bring?

Removing a keyword elseif for a simpler language?

pmetras avatar Dec 19 '22 20:12 pmetras

While simple is better, I don't know that everyone would agree that removing the keyword elseif would decrease complexity, rather than increase it.

jasoncarr0 avatar Dec 19 '22 23:12 jasoncarr0

I am not in favour of this change; I think that else ... then would be more confusing than elseif.

chalcolith avatar Dec 19 '22 23:12 chalcolith

Even if we were to agree it is both simpler and better in absolute terms, it needs to provide enough value to justify overcoming the friction of a widely-breaking change.

If the value it provides is marginal or just notional, but not significant in the sense of providing meaningful/substantial value to users of Pony, then it's not worth the breaking change.

jemc avatar Dec 20 '22 18:12 jemc

Dropping in to say I am also not in favor of this. Also here to add that ifelse would have to be removed from ifdef ... ifelse... else ... end for it to be fully removed.

rhagenson avatar Dec 20 '22 18:12 rhagenson

@SeanTAllen also mentioned in today's sync that the parser is currently written to require no lookahead, and this would potentially break that current invariant.

jemc avatar Dec 20 '22 19:12 jemc

@jasoncarr0 also mentioned that human parsers also have the same problem with lookahead :wink:

jemc avatar Dec 20 '22 19:12 jemc

Though not clearly documented in the tutorial, one can simulate this syntax with pattern matching using guards, like:

actor Main
  new create(env: Env) =>
    let x: USize = 123
    match x
    | if x < 50 => env.out.print("< 50")
    | if x < 100 => env.out.print("< 100")
    | if x < 200 => env.out.print("< 200")
    else env.out.print("= 100")
    end

pmetras avatar Dec 22 '22 14:12 pmetras