Choose Language Hide Translation Bar
Highlighted
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
Highlighted
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
Highlighted
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

Highlighted

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 );
Learn it once, use it forever!
Highlighted
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
Highlighted
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.

Article Labels

    There are no labels assigned to this post.