Names with trailing question mark
Nick Sabalausky
a at a.a
Mon Oct 3 18:13:18 PDT 2011
"bearophile" <bearophileHUGS at lycos.com> wrote in message
news:j6dgvp$1rot$1 at digitalmars.com...
> Predicates are quite common. In D I presume the standard way to write them
> is with a name like "isFoo". In other languages they are written in other
> ways:
>
>
> if (foo.isEven) {}
> if (foo.isEven()) {}
> filter!isEven(data)
>
> if (foo.evenQ) {}
> if (foo.evenQ()) {}
> filter!evenQ(data)
>
> if (foo.even?) {}
> if (foo.even?()) {}
> filter!even?(data)
>
> Other usages:
>
> contains?
> areInside ==> inside?
>
>
It's nice, and it's one of the things in Ruby that I like, but I'd be
surprised if it didn't cause parsing (or even lexing) ambiguities with ?:.
If that could be reasonably solved, I'd be in favor of it, but I'm not sure
it can.
More information about the Digitalmars-d
mailing list