cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
tom_abramov
Level V

Inserting List to List with JSL

Hello,

I dont know how to insert list to list intead of values of list to list.

Insert into makes it one big list.

I need the following to be done:

MainList = {};
AList = {"a1", "a2"};
BList = {"b1", "b2"};
//Result I need:
MainList = {{"a1", "a2"}, {"b1", "b2"}};

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Staff

Re: Inserting List to List with JSL

Please try:

NamesDefaultToHere(1);
MainList = {};
AList = {"a1", "a2"};
BList = {"b1", "b2"};
InsertInto(MainList, EvalList(List(AList)));
InsertInto(MainList, EvalList(List(BList)));
Print(MainList);

 

View solution in original post

4 REPLIES 4
ian_jmp
Staff

Re: Inserting List to List with JSL

Please try:

NamesDefaultToHere(1);
MainList = {};
AList = {"a1", "a2"};
BList = {"b1", "b2"};
InsertInto(MainList, EvalList(List(AList)));
InsertInto(MainList, EvalList(List(BList)));
Print(MainList);

 

Re: Inserting List to List with JSL

Here is another solution, related to the one provided by @ian_jmp .

 

Names Default to Here( 1 );

main list = List();

a = List( "a1", "a2" );
b = List( "b1", "b2" );

Insert Into( main list, List( a ) );
Insert Into( main list, List( b ) );

main list = Eval List( main list );

Show( main list );
txnelson
Super User

Re: Inserting List to List with JSL

This is a different way to handle this

NamesDefaultToHere(1);
MainList = {};
AList = {"a1", "a2"};
BList = {"b1", "b2"};

mainlist[1]=alist;
mainlist[2]=blist;
Jim
pmroz
Super User

Re: Inserting List to List with JSL

If you want a list of lists you might also consider using associative arrays.

MainList = associative array();
AList = {"a1", "a2"};
BList = {"b1", "b2"};
mainlist["A"] = alist;
mainlist["B"] = blist;
show(mainlist);

Result:

mainlist = ["A" => {"a1", "a2"}, "B" => {"b1", "b2"}];

Check the documentation for more information about associative arrays - they're extremely powerful.