alanrgan / rust-interpreter

0 stars 0 forks source link

Promote lists to first-class objects #7

Open alanrgan opened 7 years ago

alanrgan commented 7 years ago

The following code executes fine:

let x: list = [40..50];
print(x[0]); // output: '40'

However, operations on lists should be allowed directly:

print([40..50][0]); // should output: '40', but panics

Implementing this effectively should probably go hand-in-hand with implementing lists as first-class objects that implement an 'Enumerable' trait, whose implementation would look something along the lines of:

extend List with Enumerable<Any> {
     fn index(ind: int) : Any {
          return self.list[ind];
     }

    ... // other functions here
}

In the future, this could also allow functions like .len() to be implemented for list types.