<?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: updating list inside a function in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/updating-list-inside-a-function/m-p/826942#M100823</link>
    <description>&lt;P&gt;I think it is better idea to return the new column and then add that outside of the function call&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("\\VMSPFSFSLC001\F28_PLI\SQL\FE SQL\Data\Oxide .CSV");

op_list = List();

add_new_operation = Function({dt, col_name, op, PLmin, PLmax}, {Default Local},
	new_col = dt &amp;lt;&amp;lt; New Column(col_name,
		Character,
		"Nominal",
		Formula(
			If(/*some conditions for the value*/
			)
 		
		)
	);
	
	return(new_col);
);

sticol = add_new_operation(dt, "STI", 201405, 80, 2000);
Insert Into(op_list, sticol);

Show(op_list);


// This should also work
// Insert into(op_list, add_new_operation(dt, "STI", 201405, 80, 2000));

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Full example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

op_list = {};

add_new_operation = Function({dt, col_name}, {Default Local},
	new_col = dt &amp;lt;&amp;lt; New Column(col_name,
		Character,
		"Nominal",
		Formula(
			col_name
		)
	);
	
	return(new_col);
);

Show(op_list); // op_list = {};
Insert into(op_list, add_new_operation(dt, "name"));
Insert into(op_list, add_new_operation(dt, "age"));
Show(op_list); // op_list = {Column("name 2"), Column("age 2")};
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 12 Jan 2025 17:00:07 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2025-01-12T17:00:07Z</dc:date>
    <item>
      <title>updating list inside a function</title>
      <link>https://community.jmp.com/t5/Discussions/updating-list-inside-a-function/m-p/826932#M100822</link>
      <description>&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;I'm trying to add a new value (variable value) to a list inside a function, each time the function has been called.&lt;/P&gt;&lt;P&gt;No matter what I tried, the list is not getting any value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Adding the example of the code&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2025 16:33:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/updating-list-inside-a-function/m-p/826932#M100822</guid>
      <dc:creator>Stas</dc:creator>
      <dc:date>2025-01-12T16:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: updating list inside a function</title>
      <link>https://community.jmp.com/t5/Discussions/updating-list-inside-a-function/m-p/826942#M100823</link>
      <description>&lt;P&gt;I think it is better idea to return the new column and then add that outside of the function call&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("\\VMSPFSFSLC001\F28_PLI\SQL\FE SQL\Data\Oxide .CSV");

op_list = List();

add_new_operation = Function({dt, col_name, op, PLmin, PLmax}, {Default Local},
	new_col = dt &amp;lt;&amp;lt; New Column(col_name,
		Character,
		"Nominal",
		Formula(
			If(/*some conditions for the value*/
			)
 		
		)
	);
	
	return(new_col);
);

sticol = add_new_operation(dt, "STI", 201405, 80, 2000);
Insert Into(op_list, sticol);

Show(op_list);


// This should also work
// Insert into(op_list, add_new_operation(dt, "STI", 201405, 80, 2000));

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Full example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

op_list = {};

add_new_operation = Function({dt, col_name}, {Default Local},
	new_col = dt &amp;lt;&amp;lt; New Column(col_name,
		Character,
		"Nominal",
		Formula(
			col_name
		)
	);
	
	return(new_col);
);

Show(op_list); // op_list = {};
Insert into(op_list, add_new_operation(dt, "name"));
Insert into(op_list, add_new_operation(dt, "age"));
Show(op_list); // op_list = {Column("name 2"), Column("age 2")};
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Jan 2025 17:00:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/updating-list-inside-a-function/m-p/826942#M100823</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-01-12T17:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: updating list inside a function</title>
      <link>https://community.jmp.com/t5/Discussions/updating-list-inside-a-function/m-p/826943#M100824</link>
      <description>&lt;P&gt;And if you really want to insert into the list created outside of the function, remove {Default Local} from your function (there are also other methods) but I wouldn't recommend this. One reason being that now you have to have op_list always created before the function is called.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

op_list = {};

add_new_operation = Function({dt, col_name},
	new_col = dt &amp;lt;&amp;lt; New Column(col_name,
		Character,
		"Nominal",
		Formula(
			col_name
		)
	);
	
	Insert Into(op_list, new_col);
);

Show(op_list); // op_list = {};
add_new_operation(dt, "name");
add_new_operation(dt, "age");
Show(op_list); // op_list = {Column("name 2"), Column("age 2")};&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Jan 2025 17:18:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/updating-list-inside-a-function/m-p/826943#M100824</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-01-12T17:18:01Z</dc:date>
    </item>
  </channel>
</rss>

