I did get quite a few answers regarding this from JMP support, I'll try to write some sort of summary of those.
My question to support
If possible I would like to understand why JMP's Associative Arrays work like they do with default values, as in they delete keys if they have same value as default value. Also why it doesn't behave like this always? I have posted about this to community https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/t...
Test script with behaviour which doesn't work as intended (in my opinion):
Names Default To Here(1);
aa = [=> 0];
aa["a"] += 0;
show(aa); // aa = ["a" => 0, => 0];
aa["a"] = 0;
show(aa); // aa = [=>0];
Summary of answers from support:
I just wanted to share with you the answer I received from R&D: this behavior was implemented in associative arrays as part of modeling sets and set operations with the data structure. The particular inconsistency that you highlighted will be addressed in a future release (JMP-776).
I also provided them "example" which was very close to the situation in which I noticed the problem and they provided me with this script (I had already modified/solved this other way, but I'll share this also):
Below is slightly modified version of your example that does not use a default value for the associative array, but handles using a key that does not exist in the array. In this example, the algorithm ensures that the icons are always aligned with the proper description.
Names Default To Here(1);
//init aa
aa_status = Associative Array();
aa_status["Connection Check"] = "0";
aa_status["Folder found"] = "";
aa_status["To Delete"] = "1";
New Window("test",
Table Box(
des_ref = String Col Box("Description", aa_status << get keys),
cb_ref = Col Box("Status", {}),
)
);
//aa_status["Folder found"] = "0";
aa_status << Remove Item("To Delete");
For Each({val}, des_ref << Get,
If(Try(aa_status[val] == "0", 1),
cb_ref << Set({Icon Box("Excluded")});
,
cb_ref << Set({Icon Box("CheckCircle")});
)
);
-Jarmo