ceylon/ceylon-spec — Issue #61: Postfix or prefix exists, nonempty, is
Author: gavinking
Created: 2011-11-22 15:05:26+00:00
State: open
Labels: request for feedback

The most natural syntax for constructs like `if (exists)`, `if (nonempty)`, `if (is Type)` is the following:

if (name exists) { ... }
if (seq nonempty) { ... }
if (obj is Person) { ... }

But a long time ago I decided to go with the much less natural:

if (exists name) { ... }
if (nonempty seq) { ... }
if (is Person obj) { ... }

In order to naturally support

if (exists name = ...) { ... }
if (nonempty seq = ...) { ... }
if (is Person obj = ...) { ... }

And also because it makes `if (is)` more regular-feeling if you start considering explicit type annotations. The following would be strange:

if (Person obj is Person) { ... }

However, for *operators*, I kept the more natural postfix form:

if (!name exists) { ... }
if (!seq nonempty) { ... }
if (!obj is Person) { ... }

But the truth is it's pretty damn hard to explain why the following are not awfully inconsistent:

if (exists name) { ... }
if (!name exists) { ... }

(The "inconsistency" is more glaring now that we made the type annotation in the first form optional.)

So, there's a couple of options here:

1. keep things the way they are,
2. drop support for `if (exists name = ...) { ... }` and make you write `value name = .... ; if (exists name) { ... }`, or
3. make the operators prefix.

What should we do?