Skip to content

Strongly typed Arrays / Tuples / UDT Destructuring #66

@Greedquest

Description

@Greedquest

Related #28 & #14

Dim As Long a, b

(a , b) = foo()  'something like that

Function foo() As (Long, Long) 'maybe...

Motivation

VBA has User Defined Types, Strongly typed arrays, and variant arrays. All of these should support destructuring into variables (a,b,c = someValues. What's more, there should be compile time type inference and run time type coercion semantics. Right now only variant arrays can be destructured and you lose all the type info, both for intellisense and for casting from one type to another. They are also better for performance than relying on variant arrays citation needed

Implementation

One suggestion has been to add tuples which would be a new type primitive that can be parameterised by other types (e.g. a tuple of longs, a tuple of Foos). Named Tuples are very similar and provide dot.access to their members - like a Point2D has a .x and a .y but unlike a class, can also be destructured as x, y = getPoint2D(). To be honest if user defined types could be destructured and indexed into like arrays, then they would eliminate the need for named tuples.

As has been mentioned, this would solve the multiple function return problem in a type safe way.

Considerations

Representation in a compiled COM dll

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