Names with trailing question mark
Christophe
travert at phare.normalesup.org
Tue Oct 4 07:31:43 PDT 2011
Jacob Carlborg , dans le message (digitalmars.D:146055), a écrit :
>
> I would say it would be illegal and that the ternary operator requires a
> space before the question mark. It works like this in Ruby as well. It
> would be parsed like this:
>
> (foo?) + (foo?(a)) : b
>
> Have a look at: http://d-programming-language.org/lex.html
>
> "The source text is split into tokens using the maximal munch technique,
> i.e., the lexical analyzer tries to make the longest token it can."
>
> "For example >> is a right shift token, not two greater than tokens."
>
> It's the same here. Since "?" would be a legal symbol in a method name,
> "foo?" is the method name, not "foo" and "?".
This behavior is consistent in itself, but it is not consistent with
most common bracket langages that support ?: opperator.
That also means that you break half of the code that use ?:. You may
think it is bad writing, but I like the ?: operator to be written like
that: "a? b: c", and this has been legal for a long time now.
More information about the Digitalmars-d
mailing list