<?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: How to insert a list into another list in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386352#M63645</link>
    <description>&lt;P&gt;Yes. I've used the evallist() approach and always feel like it needs a comment to explain. In my original code (link at top) I keep changing p between insertions, so it can't just insert a reference to p.&lt;/P&gt;</description>
    <pubDate>Tue, 18 May 2021 14:37:38 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2021-05-18T14:37:38Z</dc:date>
    <item>
      <title>How to insert a list into another list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386221#M63633</link>
      <description>&lt;P&gt;In &lt;LI-MESSAGE title="Iterate through all combinations of values from ARBITRARY number of lists" uid="386030" url="https://community.jmp.com/t5/Discussions/Iterate-through-all-combinations-of-values-from-ARBITRARY-number/m-p/386030#U386030" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt; I posted an answer that required inserting a list into another list of lists. The InsertInto function unpacks the inserted list into elements, which is not what I want. I used an assignment statement to the element one beyond the end of the list, which does insert the list as an element. Another choice is to wrap the list in another list before inserting it (so it unpacks the wrapped list, and inserts the original.)&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Is there a better way to insert a list into a list? result and p are both lists.&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;STRONG&gt;result&lt;SPAN class="gmail-token gmail-punctuation"&gt;[&lt;/SPAN&gt;&lt;SPAN class="gmail-token gmail-function"&gt;N Items&lt;/SPAN&gt;&lt;SPAN class="gmail-token gmail-punctuation"&gt;(&lt;/SPAN&gt; result &lt;SPAN class="gmail-token gmail-punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="gmail-token gmail-operator"&gt;+&lt;/SPAN&gt; &lt;SPAN class="gmail-token gmail-number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="gmail-token gmail-punctuation"&gt;]&lt;/SPAN&gt; &lt;SPAN class="gmail-token gmail-operator"&gt;=&lt;/SPAN&gt; p&lt;/STRONG&gt; is a bit wordy but works and seems fairly clear that p is being stored just after the last element in the list. Good for extending, but can't insert anywhere else.&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P&gt;result={"a"};&lt;BR /&gt;p={"b","c"};&lt;BR /&gt;result[N Items( result ) + 1] = p; // wordy, but intent is clear&lt;BR /&gt;show(result);&lt;BR /&gt;/*:&lt;/P&gt;
&lt;P&gt;result = &lt;FONT color="#339966"&gt;{"a", {"b", "c"}};&lt;/FONT&gt; // good&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Insertinto( result, p )&lt;/STRONG&gt; won't work because it inserts p's elements, not p.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;result={"a"};&lt;BR /&gt;p={"b","c"};&lt;BR /&gt;insertinto( result, &amp;nbsp;p ) ; // looks right, but...&lt;BR /&gt;show(result);&lt;BR /&gt;/*:&lt;BR /&gt;result =&lt;FONT color="#FF0000"&gt; {"a", "b", "c"};&lt;/FONT&gt; // not what I want&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;insertinto( result, evallist( { p } ) )&lt;/STRONG&gt; works, but seems less readable than the assignment. Can insert anywhere but makes an extra copy.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;result={"a"};&lt;BR /&gt;p={"b","c"};&lt;BR /&gt;insertinto( result, evallist( { p } ) ) ; // makes an extra copy of the list and hard to read&lt;BR /&gt;show(result);&lt;BR /&gt;/*:&lt;BR /&gt;result =&lt;FONT color="#339966"&gt; {"a", {"b", "c"}};&lt;/FONT&gt; // good: what I want&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;edit: then I found &lt;LI-MESSAGE title="Inserting List to List with JSL" uid="248215" url="https://community.jmp.com/t5/Discussions/Inserting-List-to-List-with-JSL/m-p/248215#U248215" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt; which is the same question. It looks like similar answers, leaning towards the evallist approach.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;edit 18may2022: &lt;LI-MESSAGE title="JMP Expr() weirdness, can anyone explain?" uid="400469" url="https://community.jmp.com/t5/Discussions/JMP-Expr-weirdness-can-anyone-explain/m-p/400469#U400469" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp; has a note about builtin function names, like list() or {} being different from unknown names.&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:47:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386221#M63633</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-06-09T19:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a list into another list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386320#M63635</link>
      <description>&lt;P&gt;FWIW I always do it the EvalList ( ) way in your 2nd example. I guess you could do it this way, and not evaluate until you want / need to... not sure if this is buying you much (?)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;result = {"a"};
p = {"b", "c"};
Insert Into( result, {p} ); //don't evaluate p here... but of course p is non-static
show(result[2][1]);    //can still access elements of p if desired
Show( Eval List( result ) );  //or can eval to see the whole thing&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="brady_brady_0-1621344376429.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32921iBE08330D4BCBA446/image-size/medium?v=v2&amp;amp;px=400" role="button" title="brady_brady_0-1621344376429.png" alt="brady_brady_0-1621344376429.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 13:27:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386320#M63635</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2021-05-18T13:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a list into another list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386341#M63641</link>
      <description>&lt;P&gt;Not a direct solution but more as a work around I tend to use associative arrays, similar to what&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt;&amp;nbsp;suggested in your link.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 13:59:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386341#M63641</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-05-18T13:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a list into another list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386351#M63644</link>
      <description>&lt;P&gt;I might use that next time. It looks simpler, even if it is using a more complicated (under the covers) data structure, and since I'm already generating an index with nitems(...)+1 ... yes, it might be the better choice.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 14:33:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386351#M63644</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-05-18T14:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a list into another list</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386352#M63645</link>
      <description>&lt;P&gt;Yes. I've used the evallist() approach and always feel like it needs a comment to explain. In my original code (link at top) I keep changing p between insertions, so it can't just insert a reference to p.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 14:37:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-insert-a-list-into-another-list/m-p/386352#M63645</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-05-18T14:37:38Z</dc:date>
    </item>
  </channel>
</rss>

