The Is Operator

Bill Baxter dnewsgroup at billbaxter.com
Tue Oct 2 16:56:58 PDT 2007


Kirk McDonald wrote:
> Gregor Richards wrote:
>> 0ffh wrote:
>>
>>> Kyle G. wrote:
>>>
>>>> The code I am concerned about is "var !is null" which appears to 
>>>> translate to "var not is null" when it actually means "var is not 
>>>> null." Is there any special reason why we are unable to do "var 
>>>> isnot null" or "var is not null"?
>>>
>>>
>>> I think the syntax is perfectly logical, because the negation applies to
>>> the /operator/ and not the /operand/.Note the analogy of the statements:
>>>
>>>   (p == null)  <-->  (p is null)
>>>   (p != null)  <-->  (p !is null)
>>>
>>> Nobody would ever get try to write (i == !null), so why (i is not null)?
>>>
>>> Regards, Frank
>>
>>
>> Yeah, to me "a is not null" makes sense as an English sentence, but as 
>> an operator it seems like "a is (not null)". (not null) would have to 
>> evaluate to ... 1? So this would be a is 1, which isn't what we want 
>> at all.
>>
>> Suffice to say D !is English.
>>
>>  - Gregor Richards
> 
> I'd like to point out that "is not" is exactly what the Python 
> equivalent of "!is" is.
> 
> http://docs.python.org/ref/comparisons.html
> 
> if a is not None:
>     foo()
> 
> Likewise, it also uses "not in".

And also the binary boolean operators 'and' and 'or'.

    if you is not None and I is not finished or they is happy:
         goto_skool()

See reads just like English!

--bb



More information about the Digitalmars-d mailing list