Skip to content

Support indexing with square bracket syntax #173

Description

@ywangd

Today, indexing into an array uses syntax like array.0. This syntax also works if the index is a variable, i.e. array.i. The issue is that the variable i is resolved in the global namespace, i.e. you need something like:

let i = 0
echo array.i

If we want to have better support for OO style language, this syntax conflicts with that of the object method call, i.e. foo.bar where foo is an object and bar is a method of foo. Basically, the expression foo.bar is ambiguous because it is clear whether it is a array/dict member access or object method call, especially if we want to have member methods for array/dict. In most other languages, this is solved by having the syntax of foo.bar dedicated to object method call and foo[bar] for member access. So the proposal is to have something like the follows:

// array or dict element access
a[0]
a.0
a[b]   // b is resolved
a.@b  // b is not resolved
// method call
a.b   // b is not resolved

This is useful if we want to have full OO support, which by itself is a question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions