http://docs.polserver.com/pol097/objref.php#Dictionary
states that dictionary.exists(key) returns: error/int if exists, returns count of matching key
it's not true - this method returns boolean: 1 if key exists 0 if not.
[not a bug] Docs dictionary bug
Moderator: POL Developer
Re: Docs dictionary bug
Both you and the documentation are correct. Because dictionaries are maps, there can only be zero or one matching entry in the dictionary for any key.
will result in:
Why? Because there is exactly 1 key of "apple" in the dictionary, 1 key of "banana", 1 key of "cookie", and 0 keys of "dogfood."
Code: Select all
var d := dictionary;
d["apple"] := "one";
d["banana"] := "two";
d["cookie"] := "three";
print("exists: "+d.exists("apple"));
print("exists: "+d.exists("banana"));
print("exists: "+d.exists("cookie"));
print("exists: "+d.exists("dogfood"));
Code: Select all
exists: 1
exists: 1
exists: 1
exists: 0
Re: Docs dictionary bug
well, maybe it's my poor english skill, but "returns: error/int" and "if exists, returns count of matching key" made me think, that method returns integer only if key exists and error if it doesnt exist.
Re: Docs dictionary bug
Aaah. I can see how that could be worded better. "error" is typically reserved for actual errors. Since testing for whether a key exists even when it doesn't is not an error, but in fact exactly what it's intended for, it returns 0. "error" is returned for invalid parameters.