Hey guys,
I'm trying to add a new value (variable value) to a list inside a function, each time the function has been called.
No matter what I tried, the list is not getting any value.
Any advice?
Adding the example of the code
I think it is better idea to return the new column and then add that outside of the function call
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 << 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));
Full example
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 << 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")};
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.
Names Default To Here(1); dt = Open("$SAMPLE_DATA/Big Class.jmp"); op_list = {}; add_new_operation = Function({dt, col_name}, new_col = dt << 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")};