Skip to content

add a new syntactic category: tuples #131

@BurntSushi

Description

@BurntSushi

Regardless of whether issue #28 is accepted, arrays can only contain values of a single data type. While data types can still be mixed at the hash level, it may still be desirable to compactly represent an array of mixed data types. We can do this with tuples. So that while this is illegal

usergroups = [[0, "root", "root"], [1, "bin", "root"]]

with tuples, it could be represented as

usergroups = [(0, "root", "root"), (1, "bin", "root")]

In particular, the type of the above is an array of int * string * string if #28 is accepted, or simply array in the current spec.

The semantics of a tuple is that its type is the product of the types of its elements. This not only makes it an ordered type, but it fixes the length as well. So that this would not be allowed:

something = [("a", "b"), ("x", "y", "z")]

since the first tuple has type string * string and the latter has type string * string * string.

I also propose that tuples with less than 2 elements be forbidden. Any attempt to create them should result in an error.

The actual syntax of a tuple is precisely the same as an array, except with () instead of []. Tuples may contain arrays and arrays may contain tuples.

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