Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 5
    The C conditional expression (commonly known as the ternary operator) has three operands: expr1 ? expr2 : expr3. If expr1 evaluates to true, expr2 is evaluated and is the result of the expression. Otherwise, expr3 is evaluated and provided as the result. This is from the ANSI C Programming Language section 2.11 by K&R. My Go solution preserves these specific semantics. @Wolf Can you clarify what you are suggesting? Commented May 31, 2017 at 1:26
  • 5
    "simply" in this case looks more like "complicatedly" Commented Dec 10, 2020 at 19:50
  • 11
    Why add "else"? a := func() int { if test { return 1 } return 2 }() should work or am I wrong? Commented Apr 15, 2021 at 5:12
  • 2
    I removed the else block. Thanks. I also removed "simply" because it sounds pedantic. Commented Oct 31, 2023 at 13:05
  • 1
    it still amazes me how golang designers think :::::::::::::::::::::::: :::::::::::::::: ::::::: :::::::::::: ::::::::::: ::::::::: a := func() int { if test { return 1 } return 2 }() :::::::::::: :::::::::::: ::::::::::: :::::::::::: is any better than a hypothetical ::::::::::::::::: :::::::::::::::: ::::::: :::::::::::: ::::::::::::::::::::: :: :::::::::: a := func() int { return test ? 1 : 2 }() Commented Mar 13, 2024 at 21:18