Skip to content

Miscellaneous syntax improvements

jckarter edited this page Nov 25, 2010 · 6 revisions

Random ideas for syntax improvements:

  • Make the final ";" in an statement list optional, similar to the optional final "," in an expression list:
    • { foo() }
    • { foo(); bar() }
  • Make { } indicate a nullary statement lambda, implying the () =>:
    • each(bar, { bas() });
    • This would cause an ambiguity in the parsing of if statements and expressions:
      • if (x) { y() } else { z() }
      • However, since an if expression returning lambdas is currently not valid (the two lambdas are of different incompatible types) the ambiguity could always be resolved in favor of the statement form. The ambiguity is still a bad trap
  • Make the parens around if, while, for and switch optional:
    • if x { y() } else { z() }
    • for x in y { z() }
    • while x { y() }
    • switch x { case y: z() }
    • Looks a bit awkward in the single-statement case, especially with infix expressions:
      • if x y();
      • while x == y z += w;
      • Brace syntax could be made mandatory (as in Perl and Go), with an exception (or keyword replacement) for else if. if expression syntax could use a then keyword, which would make it completely unambiguous from if statements, even with the optional () => change mentioned above:
        • if x { y() } else { z() } — if statement
        • if x then y() else z() — if expression
        • if x then { y() } else { z() } — if expression returning lambdas
          • still a pretty hair-splitting difference between the statement and lambda-returning forms