Hacker News new | past | comments | ask | show | jobs | submit login

Yes. "[]" would denote the operator for accessing element of collection associated with key/index k by [k] syntax. Similarly "[]=" would denote operator for storing element under a given key/index.

E.g. in python these would correspond to a custom type implementing https://docs.python.org/3/reference/datamodel.html#object.__... & https://docs.python.org/3/reference/datamodel.html#object.__...




OK, yeah, I get it now.

so if I defined my own map type (e.g. orderedmap[T] that kept things in the order they were added) then I'd need to write code for the [] operator to access an element, is that right?

I guess I'm not really sure how that differs from declaring orderedmap(T) (as it is in the proposal). Why do I need to overload one and not the other?




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: