Skip to content

Matrix literals #102

@FortranFan

Description

@FortranFan

As proposed by a reader at comp.lang.fortran: https://groups.google.com/d/msg/comp.lang.fortran/m6qz7hC4a7M/78maOb9uEgAJ
(see the thread for further comments and discussion)

Adding matrix literals
This is mostly a quality of life thing, but something like

INTEGER, DIMENSION(2, 2) :: A = [1, 2; 3, 4]
representing the matrix
/ 1 2 \
\ 3 4 /

is, to me, a lot more readable than
INTEGER, DIMENSION(2, 2) :: A = TRANSPOSE(RESHAPE([1, 2, 3, 4], [2, 2]))
This could even be extended to more complex arrays by, for instance, repeating
semicolons, eg.
INTEGER, DIMENSION(2, 2, 2) :: B = [1, 2; 3, 4;; 5, 6; 7, 8]
One issue with this syntax is of course that the values are given row major,
which is different from the memory layout of Fortran an thus also the way
RESHAPE works.

Alternatively [1, 2; 3, 4] could represent
/ 1 3 \
\ 2 4 /

Metadata

Metadata

Assignees

No one assigned

    Labels

    Clause 10Standard Clause 10: Expressions and assignment

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions