source-academy / cs1101s

1 stars 0 forks source link

What is the difference between lists and arrays? #8

Open mrqorib opened 4 years ago

mrqorib commented 4 years ago

Question: Lists and arrays seem to be quite similar, so I'd like to ask -- what are the differences? When do you use one over the other? Piazza: https://piazza.com/class/kas136yscf8605?cid=551

mrqorib commented 4 years ago

Answer: lists are just series of pairs such that list(e1, e2, e3) is represented by pair(e1, pair(e2, pair(e3, null))). Pairs are internally represented with arrays of size 2. Thus, the textual representation of the above list is [e1, [e2, [e3, null]]].