The Is Operator

Kirk McDonald kirklin.mcdonald at gmail.com
Tue Oct 2 16:51:25 PDT 2007


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".

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org



More information about the Digitalmars-d mailing list