In a previous article, I wrote about how it was difficult to produce a 2D list in Copper due to the ownership dilemma. The solution at the time was to write a singly-linked list in Copper. It turns out, there is a better approach, one that will also allow us to create any multi-dimensional list.
Tag: linked lists
Suppose you wanted to create a 2-dimensional list. This can be easily done with the list constructor. ex:
mylist = list(list(9))
Now suppose we wanted to access the item in the second dimension of the list. Lists are special in that they are objects that contain other objects without themselves containing variables. To access an item in the list, we use the item_at() system function. This returns an object. Performing it once will return the child list. From there, we can call item_at() in succession to access the item of interest:
myitem = item_at(item_at(mylist: 0) 0)
A number of things have changed with regards to the internals. A great deal of time has been spent trying to optimize the engine, resulting in some interesting discoveries.
Lists are tuples are very common features for languages. Arrays and lists have been around for some time, so they are almost expected. Python does away with arrays, understandably so, and it almost makes little sense to keep they around for Copper. Tuples, on the other hand, seem primarily for mental models, but can be useful in preventing misuse and accidental deletions or additions of elements as well as providing convenient means for extraction. They sort of fill the gaps for simplicity that lists, arrays, and general objects don’t fill. Both of these should be discussed in detail.