Task
Implement List[T] as a built-in generic collection type.
Acceptance criteria
- Type syntax:
List[Int], List[Str], etc.
- Non-empty literal infers element type:
[1, 2, 3] → List[Int]
- Empty literal requires annotation:
var xs: List[Int] = []
- Mixed-type literals are a compile-time error
- Methods:
len(), contains(value), get(index), get(index, default), add(value), remove(index)
- Mutating methods (
add, remove) require var receiver — compile-time error on const
- Negative indexing:
xs[-1] → last element; out-of-bounds → IndexError
Spec
See PDP-009: Collection Types.
Task
Implement
List[T]as a built-in generic collection type.Acceptance criteria
List[Int],List[Str], etc.[1, 2, 3]→List[Int]var xs: List[Int] = []len(),contains(value),get(index),get(index, default),add(value),remove(index)add,remove) requirevarreceiver — compile-time error onconstxs[-1]→ last element; out-of-bounds →IndexErrorSpec
See PDP-009: Collection Types.