<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Associative arrays and removal of keys with value same as default value in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/m-p/466884#M71066</link>
    <description>&lt;P&gt;I did get quite a few answers regarding this from JMP support, I'll try to write some sort of summary of those.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question to support&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;If possible I would like to understand why JMP's Associative Arrays work like they do with default values,&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;as in they delete keys if they have same value as default value. Also why it doesn't behave like this&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;always? I have posted about this to community &lt;A href="https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/td-p/461239" target="_blank"&gt;https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/td-p/461239&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Test script with behaviour which doesn't work as intended (in my opinion):&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
aa = [=&amp;gt; 0];
aa["a"] += 0;
show(aa); // aa = ["a" =&amp;gt; 0, =&amp;gt; 0];
aa["a"] = 0;
show(aa); // aa = [=&amp;gt;0];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Summary of answers from support:&lt;/P&gt;
&lt;P class="cs2654ae3a"&gt;&lt;EM&gt;&lt;SPAN class="csa33de6751"&gt;I just wanted to share with you the answer I received from R&amp;amp;D: this behavior was implemented in associative arrays as part of modeling sets and set operations with the data structure. &lt;/SPAN&gt;&lt;/EM&gt;&lt;EM&gt;&lt;SPAN class="csa33de6751"&gt;The particular inconsistency that you highlighted will be addressed in a future release (JMP-776).&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P class="cs2654ae3a"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="cs2654ae3a"&gt;&lt;SPAN class="csa33de6751"&gt;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):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="cse77a638e"&gt;&lt;EM&gt;&lt;SPAN class="csa33de6751"&gt;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. &amp;nbsp;In this example, the algorithm ensures that the icons are always aligned with the proper description.&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P class="cs2654ae3a"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;&amp;lt; get keys),
              cb_ref = Col Box("Status", {}),
       )
);
 
//aa_status["Folder found"] = "0";
aa_status &amp;lt;&amp;lt; Remove Item("To Delete");
For Each({val}, des_ref &amp;lt;&amp;lt; Get,
       If(Try(aa_status[val] == "0", 1),
              cb_ref &amp;lt;&amp;lt; Set({Icon Box("Excluded")});
       ,
              cb_ref &amp;lt;&amp;lt; Set({Icon Box("CheckCircle")});
       )
);
 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2022 06:57:10 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2022-03-04T06:57:10Z</dc:date>
    <item>
      <title>Associative arrays and removal of keys with value same as default value</title>
      <link>https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/m-p/461239#M70626</link>
      <description>&lt;P&gt;Just noticed new behaviour (for me) that when using Associative Arrays() and the key you have, has the same value as default value, the key might disappear. I noticed this because I was using Associative Array to collect different status messages (default value was set to 0) and then used that associative array to build user interface after collecting statuses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A title="JMP Help" href="https://www.jmp.com/support/help/en/16.2/#page/jmp/create-associative-arrays.shtml" target="_blank" rel="noopener"&gt;Create Associative Arrays&lt;/A&gt;&amp;nbsp;does have following note so this is expected behaviour:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class="Note"&gt;&lt;STRONG&gt;&lt;SPAN class="Note"&gt;Note:&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;If a key’s value is the default value, then the key is dropped because any key will return the default value.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P class="Note"&gt;One example where that Note doesn't seem to hold truth:&lt;/P&gt;
&lt;P class="Note"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
aa = [=&amp;gt; 0];
aa["a"] += 0;
show(aa); // aa = ["a" =&amp;gt; 0, =&amp;gt; 0];
aa["a"] = 0;
show(aa); // aa = [=&amp;gt; 0];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="Note"&gt;Any ideas why it works like this? Due to this behaviour (keys getting deleted) I will most likely give up with default values in Associative Array (for now) so I can have same behaviour in all of my scripts and just handle the errors caused by keys which are not found from the Associative Array.&lt;/P&gt;
&lt;P class="Note"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;I would prefer the keys not being removed at all, when they have same value as default value. This is most likely so deeply built into JMP for some good reason (optimizations?) that I suspect it won't be changed&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:10:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/m-p/461239#M70626</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-06-09T18:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Associative arrays and removal of keys with value same as default value</title>
      <link>https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/m-p/461283#M70630</link>
      <description>&lt;P&gt;No idea. It isn't the behavior I'd expect either.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;aa = [=&amp;gt; 0];
aa["a"] += 0;
show(aa); // aa = ["a" =&amp;gt; 0, =&amp;gt; 0];
aa["a"] -= aa["a"] ;
show(aa); // aa =  ["a" =&amp;gt; 0, =&amp;gt; 0]; ! good ?&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My normal usage is similar, except I'd only use +=1 to count occurrences, so I'd never see it.&lt;/P&gt;
&lt;P&gt;Also, don't use a { }, [ ], or [ =&amp;gt; ] for an initial value. It does not work the way you expect, though it may shed some light on the issue (it changes the default value without adding an element.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For future-proofing, in case this gets changed for the better, I'd use explicit &amp;lt;&amp;lt;remove("a") if that's what I want, and if I want to modify a default value, I'd use explicit &amp;lt;&amp;lt;getDefault and &amp;lt;&amp;lt;setDefault.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 13:04:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/m-p/461283#M70630</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-02-16T13:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Associative arrays and removal of keys with value same as default value</title>
      <link>https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/m-p/466884#M71066</link>
      <description>&lt;P&gt;I did get quite a few answers regarding this from JMP support, I'll try to write some sort of summary of those.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question to support&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;If possible I would like to understand why JMP's Associative Arrays work like they do with default values,&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;as in they delete keys if they have same value as default value. Also why it doesn't behave like this&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;always? I have posted about this to community &lt;A href="https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/td-p/461239" target="_blank"&gt;https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/td-p/461239&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Test script with behaviour which doesn't work as intended (in my opinion):&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
aa = [=&amp;gt; 0];
aa["a"] += 0;
show(aa); // aa = ["a" =&amp;gt; 0, =&amp;gt; 0];
aa["a"] = 0;
show(aa); // aa = [=&amp;gt;0];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Summary of answers from support:&lt;/P&gt;
&lt;P class="cs2654ae3a"&gt;&lt;EM&gt;&lt;SPAN class="csa33de6751"&gt;I just wanted to share with you the answer I received from R&amp;amp;D: this behavior was implemented in associative arrays as part of modeling sets and set operations with the data structure. &lt;/SPAN&gt;&lt;/EM&gt;&lt;EM&gt;&lt;SPAN class="csa33de6751"&gt;The particular inconsistency that you highlighted will be addressed in a future release (JMP-776).&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P class="cs2654ae3a"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="cs2654ae3a"&gt;&lt;SPAN class="csa33de6751"&gt;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):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="cse77a638e"&gt;&lt;EM&gt;&lt;SPAN class="csa33de6751"&gt;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. &amp;nbsp;In this example, the algorithm ensures that the icons are always aligned with the proper description.&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P class="cs2654ae3a"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;&amp;lt; get keys),
              cb_ref = Col Box("Status", {}),
       )
);
 
//aa_status["Folder found"] = "0";
aa_status &amp;lt;&amp;lt; Remove Item("To Delete");
For Each({val}, des_ref &amp;lt;&amp;lt; Get,
       If(Try(aa_status[val] == "0", 1),
              cb_ref &amp;lt;&amp;lt; Set({Icon Box("Excluded")});
       ,
              cb_ref &amp;lt;&amp;lt; Set({Icon Box("CheckCircle")});
       )
);
 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 06:57:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Associative-arrays-and-removal-of-keys-with-value-same-as/m-p/466884#M71066</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-03-04T06:57:10Z</dc:date>
    </item>
  </channel>
</rss>

