Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lyrachord opened this issue Dec 14, 2022 · 10 comments
Open

Comments

@lyrachord
Copy link

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.

@SeanTAllen
Copy link
Member

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.

@jemc
Copy link
Member

jemc commented Dec 14, 2022

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

@pmetras
Copy link

pmetras commented Dec 19, 2022

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

Removing a keyword elseif for a simpler language?

@jasoncarr0
Copy link

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

@chalcolith
Copy link
Member

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

@jemc
Copy link
Member

jemc commented Dec 20, 2022

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.

@rhagenson
Copy link
Member

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.

@jemc
Copy link
Member

jemc commented Dec 20, 2022

@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
Copy link
Member

jemc commented Dec 20, 2022

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

@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Dec 20, 2022
@pmetras
Copy link

pmetras commented Dec 22, 2022

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

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Dec 22, 2022
@SeanTAllen SeanTAllen changed the title proposal syntax else ... then for else keyword in conditional branchs proposal syntax else ... then for else keyword in conditional branches Dec 23, 2022
@jemc jemc removed the discuss during sync Should be discussed during an upcoming sync label Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants