Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does appending a list to another list in F# incur copying of underlying objects or just the pointers?

I've always thought that appending a list to another one meant copying the objects from the first list and then pointing to the appended list as described for example here. However, in this blog post and in its comment, it says that it is only the pointers that are copied and not the underlying objects. So what is correct?

like image 937
Christian Avatar asked Aug 19 '12 11:08

Christian


People also ask

What happens if you append a list to a list?

append() adds a list inside of a list. Lists are objects, and when you use . append() to add another list into a list, the new items will be added as a single object (item).

Does append change the list?

append() the original list is modified. The method does not create a copy of the list – it mutates the original list in memory.

Can you append a list to another list Python?

It's very easy to add elements to a List in Python programming. We can append an element at the end of the list, insert an element at the given index. We can also add a list to another list. If you want to concatenate multiple lists, then use the overloaded + operator.

Is append a list function in Python?

The Python List append() method is used for appending and adding elements to the end of the List. Parameters: item: an item to be added at the end of the list.


1 Answers

Drawing from Snowbear's answer, a more accurate image of combining two lists (than the one presented in the first referred article in the question) would be as shown below.

let FIRST = [1;2;3]
let SECOND = [4;5;6]
let COMBINED = FIRST @ SECOND

A more accurat description of appended list

like image 130
Christian Avatar answered Oct 27 '22 10:10

Christian