Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Because `.foo` means `[‘foo’]` and because you can easily make sequences out of them (if you write `{ ... i1 = v1, v2, ... }` then `v2` automatically gets the “next” natural number as a key) the ergonomics make them usable as structures and arrays easily. Also the ‘:foo()` syntax binds the LHS of the operator as the first parameter for a method call, and metamethods allow you to easily implement inheritance / dispatch / etc.

It’s more about ergonomics than availability.



Not a full equivalence, but this[0] gets you x.foo, x.bar ergonomics as opposed to x['foo'] etc.

[0] https://docs.python.org/3/library/types.html#types.SimpleNam...


> `.foo` means `['foo']`

Ruby does the same, except that it's `[:'foo']` because Ruby has two string types because fuck you.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: