"contains" doesn't seem to work the way I thought it worked

Banana Lord

Member
When I got stuck on a problem I was working on today I started testing basic cases with code from the wiki and ran into something odd (or, something that seems odd to me). Some code copied from the wiki:

PHP:
boolean [string, string] props;
props[ "dog", "mammal" ] = true; 
props[ "dog", "pet" ] = true; 
props[ "dog", "fun" ] = false;

props contains "dog";

This gives an error: "Expected ;, found contains ()". Am I missing something stupidly obvious here? On a related note, is there a way of doing a "does NOT contain" operation? Or should I just do "if(map contains key == false)"?
 

Bale

Minion
Am I missing something stupidly obvious here?

Yes. "contains" is an operator and needs to be used as an operator. Try this:

Code:
if(props contains "dog") print("dog");


On a related note, is there a way of doing a "does NOT contain" operation?

Sure, we've got this other operator "!" that means not. Put that in front like this:

Code:
if(!(props contains "cat")) print("no cat");

Those parentheis are necessary because ! has a higher order of precedence than contains.
 
Top