Progress on the list object

Posted: March 29th, 2011 | Author: Mars | Filed under: Progress | Comments Off

I’ve implemented the lookup and element-assignment operations on the list now. Lookup uses the subscript protocol: instead of calling a method, you use brackets to look up the element by index. That is, the list’s default operation is the lookup, like this:

var names = ["Joe", "Erin", "Bill", "Colin", "Tessa"]
io->print( names[2] )
…prints the text Bill to the console.

In order to replace one of these values, one calls the assign method:
names->assign(1, "Jessie")

I am thinking about sugaring this so that one can assign to a bracket subscript instead, but it’s not a high priority. It would look like this:
names[1] = "Jessie"

The remaining methods the list object needs are insert, remove, concatenate, and of course iterate.


Comments are closed.