Skip to content

[start:end:inc] array constructor  #329

Open
@PierUgit

Description

@PierUgit

It's quite common to need an array forming an arithmetic sequence, and the current way is with the implied do feature:
a = [(i,i=start,end,inc)]

Instead, we may have the matlab-like notation:
a = [start:end:inc]

It's more readable, and there's no need of an index variable.

My initial idea was just a = start:end:inc without the square brackets, but I think they are needed to avoid any ambiguity with the array slices: array(1:10:2) and array([1:10:2]) would return the same result, but would be fundamentally different, the former being a classical array slice, and the latter being an array indexing. But maybe there would be no ambiguity for the compilers, and 1:10:2 should never be interpreted as an array constructor in array(1:10:2)

Nonetheless requiring the square brackets has another advantage: there's no need to define precedences between : and the arithmetic operators:
2 * start:end:inc could be 2*(start:end:inc) or (2*start):end:inc
2 * [start:end:inc] is unambiguous

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions