[not a bug] Docs dictionary bug

Bug Reports relating to the 097 core are moved to this forum once solved.

Moderator: POL Developer

Locked
Targun
Neophyte Poster
Posts: 30
Joined: Wed Jul 23, 2008 8:03 am

[not a bug] Docs dictionary bug

Post by Targun » Sun Nov 09, 2008 1:00 am

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.

Luth
Former Developer
Posts: 200
Joined: Mon Jan 30, 2006 8:10 am

Re: Docs dictionary bug

Post by Luth » Sun Nov 09, 2008 3:12 pm

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.

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"));
will result in:

Code: Select all

exists: 1
exists: 1
exists: 1
exists: 0
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."

8)

Targun
Neophyte Poster
Posts: 30
Joined: Wed Jul 23, 2008 8:03 am

Re: Docs dictionary bug

Post by Targun » Tue Nov 11, 2008 1:45 am

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.

Luth
Former Developer
Posts: 200
Joined: Mon Jan 30, 2006 8:10 am

Re: Docs dictionary bug

Post by Luth » Tue Nov 11, 2008 1:05 pm

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.

Locked