Your Digital Media Has Never Looked So Good

 
EnTerr
** Valued Community Member **
Topic Author
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

roAssociativeArray.append() with duplicate keys [solved]

Mon Jan 06, 2014 4:15 pm

Documentation is laconic
Append(aa as Object)
Append an AssociativeArray to this one.

It is unclear what happens if the same keys are present in both dictionaries? E.g. a={k:"a"} and b={k:"b"}, after a.append(b), should that be:
a) error during update
b) a.k = "a" (a prevails)
c) a.k = "b" (b prevails)
d) behavior undefined (can change in the future)

I tested and current behavior seems to be (c), as if a loop over b has been ran, doing a.AddReplace(). Roku*, can you state if this will be the behavior to rely on and document it?

PS. method probably should have been named "update()" since this implies new values win, compare to python's

PPS. there is a bug in ".append()" in that if one passes non-roAssociativeArray argument, nothing happens (not even an error). That does not sound meaningful by design. Currently by the doc it is "Append(aa as Object)" but i can feed it number, string, bool, function... with no apparent effect. So seems to be more of "dynamic" type
Last edited by EnTerr on Sun Sep 21, 2014 3:10 pm, edited 2 times in total.
 
EnTerr
** Valued Community Member **
Topic Author
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: roAssociativeArray.append() with duplicate keys

Wed Jan 15, 2014 1:21 am

Bump.

Somebody from RokuCo, can you confirm this is guaranteed behavior?
It seems logical but can i rely on it.
 
User avatar
RokuJoel
Posts: 1758
Joined: Mon Nov 14, 2011 5:22 pm

Re: roAssociativeArray.append() with duplicate keys

Wed Jan 15, 2014 5:32 pm

Hi Enterr, I filed a bug on the last part of your posting (the lack of type checking) the day after you initially posted it.

Documentation - I can point that out to the documentation people.

- Joel
 
EnTerr
** Valued Community Member **
Topic Author
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: roAssociativeArray.append() with duplicate keys

Wed Jan 15, 2014 11:35 pm

RokuJoel wrote:
Hi Enterr, I filed a bug on the last part of your posting (the lack of type checking) the day after you initially posted it.
Documentation - I can point that out to the documentation people.


Thanks Joel -
bump was regarding answer to my question. I guess the implication of what you are saying is that the new values are supposed to override old values for overlapping keys?

By the way, here is another one for reporting: roArray.append() acts the same way as append for roAA. For example, pop-quiz: what does this do:
a = [1,2,3]
a.append(4)
print a
a) print 1 2 3 4
b) error message

People coming from other languages (like python) will guess (a). The ones who have read the documentation and programmed only a little (like me) will expect (b). But the reality right now is
(c) none of the above, it will print 1 2 3
 
EnTerr
** Valued Community Member **
Topic Author
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: roAssociativeArray.append() with duplicate keys

Thu Feb 13, 2014 7:37 pm

So what does it take to get an answer?
Am i asking too difficult of a question? Or is it my poor command of English.
 
User avatar
RokuJoel
Posts: 1758
Joined: Mon Nov 14, 2011 5:22 pm

Re: roAssociativeArray.append() with duplicate keys

Fri Feb 14, 2014 12:53 pm

Hi, as you noted "b" prevails. That would be the standard behavior that I don't think we would want to change. Of course, its software, so everything can change if someone decides to make it so as a matter of policy, or accidentally breaks something...

- Joel
 
EnTerr
** Valued Community Member **
Topic Author
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: roAssociativeArray.append() with duplicate keys

Fri Feb 14, 2014 1:21 pm

RokuJoel wrote:
Hi, as you noted "b" prevails. That would be the standard behavior that I don't think we would want to change. Of course, its software, so everything can change if someone decides to make it so as a matter of policy, or accidentally breaks something...

Hi - appreciate an answer but since you don't seem certain, please run this by "a higher power" and get definitive answer that it will not in fact change.

It is customary to fix such details in the API and document that too. As i pointed out this is the guaranteed behavior in other languages (although there they use more fortunate name like ".update()" which just by name implies the behavior).

I will give you a reason so my question does not seem capricious: i intend to use this for (home-grown, class-less) object inheritance, so that new methods override parent's existing methods.
 
User avatar
TheEndless
** Valued Community Member **
Posts: 9231
Joined: Mon Oct 04, 2004 10:15 am
Location: US
Contact:

Re: roAssociativeArray.append() with duplicate keys

Fri Feb 14, 2014 1:40 pm

EnTerr wrote:
I will give you a reason so my question does not seem capricious: i intend to use this for (home-grown, class-less) object inheritance, so that new methods override parent's existing methods.

I'm already using it like this as a fundamental feature of my framework, so I'm counting on it not changing! Looping through the keys individually is significantly slower (which, incidentally, can have a huge impact on the framerate of 2D API implementations).
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
 
User avatar
RokuJoel
Posts: 1758
Joined: Mon Nov 14, 2011 5:22 pm

Re: roAssociativeArray.append() with duplicate keys

Sun Feb 16, 2014 3:27 pm

There will never be a definitive answer that something will not change. Anything that is likely to break channels, the way changing this would break channels, is unlikely to change, but that doesn't mean it won't change if there is a pressing reason to do so.

- Joel
 
EnTerr
** Valued Community Member **
Topic Author
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

[Solved!] roAssociativeArray.append() with duplicate keys

Sun Jun 08, 2014 4:16 pm

I notice that documentation has been updated to say
ifAssociativeArray.Append(aa as Object) wrote:
... If any key in aa are already associated with a value in this AssociativeArray, the current value is discarded and is replaced with the value in aa.
So it is behavior (B), the new AA overrides old AA content in case of overlapping keys. As any experienced developer would expect but now is in the RTFM and can be relied upon.

My gratitude goes to the forum's patron saint, RokuMarkn - thank you!
 
User avatar
TheEndless
** Valued Community Member **
Posts: 9231
Joined: Mon Oct 04, 2004 10:15 am
Location: US
Contact:

Re: [Solved!] roAssociativeArray.append() with duplicate key

Sun Jun 08, 2014 6:37 pm

EnTerr wrote:
I notice that documentation has been updated to say
ifAssociativeArray.Append(aa as Object) wrote:
... If any key in aa are already associated with a value in this AssociativeArray, the current value is discarded and is replaced with the value in aa.
So it is behavior (B), the new AA overrides old AA content in case of overlapping keys. As any experienced developer would expect but now is in the RTFM and can be relied upon.

My gratitude goes to the forum's patron saint, RokuMarkn - thank you!

It's probably worth noting that case matters in this instance as well. So, if you have a key named "Test" and you append an AA with a key named "test", you'll end up with two separate keys.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
 
renojim
** Valued Community Member **
Posts: 3472
Joined: Mon Feb 15, 2010 1:35 pm

Re: [Solved!] roAssociativeArray.append() with duplicate key

Mon Jun 09, 2014 10:51 am

TheEndless wrote:
It's probably worth noting that case matters in this instance as well. So, if you have a key named "Test" and you append an AA with a key named "test", you'll end up with two separate keys.

That's interesting. Could that be considered a bug? i thought Associative Arrays were case insensitive by default, hence the SetModeCaseSensitive interface. Which one do you get if you Lookup "test"? How about "tESt"?

-JT
 
EnTerr
** Valued Community Member **
Topic Author
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: [Solved!] roAssociativeArray.append() with duplicate key

Mon Jun 09, 2014 11:06 am

renojim wrote:
That's interesting. Could that be considered a bug?

I would consider this a bug - if it were true. But i am unable to reproduce the behavior:
BrightScript Debugger> d = {}
BrightScript Debugger> d["Test"] = "Test"
BrightScript Debugger> ?d
Test: Test

BrightScript Debugger> d2 = {}
BrightScript Debugger> d2["test"] = "test"
BrightScript Debugger> ? d2
test: test

BrightScript Debugger> d.append(d2)
BrightScript Debugger> ?d
test: test

PS. Case (in)sensitivity is a PITA, in general.
 
User avatar
squirreltown
Posts: 864
Joined: Sun Apr 21, 2013 2:20 pm

Re: roAssociativeArray.append() with duplicate keys

Mon Jun 09, 2014 12:26 pm

TheEndless wrote:
It's probably worth noting that case matters in this instance as well. So, if you have a key named "Test" and you append an AA with a key named "test", you'll end up with two separate keys.


So according to EnTerr's test it seems this is not the case unless you call setModeCaseSensitve? The key replaced the other.

Brightscript is case-insensitive except for the registry, right? Anything else?
Kinetics Screensavers
 
User avatar
TheEndless
** Valued Community Member **
Posts: 9231
Joined: Mon Oct 04, 2004 10:15 am
Location: US
Contact:

Re: roAssociativeArray.append() with duplicate keys

Mon Jun 09, 2014 12:30 pm

Sorry, it seems case sensitivity is on when parsing a JSON string, so this is only true if you call the SetModeCaseSensitive() explicitly, or if your AA comes from a parsed JSON string.

For example:
BrightScript Debugger> test1 = ParseJSON("{" + Chr(34) + "Test" + Chr(34) + ": true}")
BrightScript Debugger> test2 = ParseJSON("{" + Chr(34) + "test" + Chr(34) + ": false}")
BrightScript Debugger> ?test1
Test: true

BrightScript Debugger> ?test2
test: false

BrightScript Debugger> test2.Append(test1)
BrightScript Debugger> ?test2
Test: true
test: false
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)

Who is online

Users browsing this forum: No registered users and 7 guests