In Iterate through all combinations of values from ARBITRARY number of lists 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.)
Is there a better way to insert a list into a list? result and p are both lists.
result[N Items( result ) + 1] = p 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.
result={"a"};
p={"b","c"};
result[N Items( result ) + 1] = p; // wordy, but intent is clear
show(result);
/*:
result = {"a", {"b", "c"}}; // good
Insertinto( result, p ) won't work because it inserts p's elements, not p.
result={"a"};
p={"b","c"};
insertinto( result, p ) ; // looks right, but...
show(result);
/*:
result = {"a", "b", "c"}; // not what I want
insertinto( result, evallist( { p } ) ) works, but seems less readable than the assignment. Can insert anywhere but makes an extra copy.
result={"a"};
p={"b","c"};
insertinto( result, evallist( { p } ) ) ; // makes an extra copy of the list and hard to read
show(result);
/*:
result = {"a", {"b", "c"}}; // good: what I want
Craige