Skip to content

Syntax proposal for making string dicts easier to write #1392

Open
@blerner

Description

@blerner

Currently we have two constructors for string dicts:

[string-dict1: "a", 1, "b", 2, "c", 3] # This is the old API
[string-dict2: {"a"; 1}, {"b"; 2}, {"c"; 3}] # This is the new API using tuples

The first one is lousy because of potential arity errors (if you specify an odd number of arguments). The second avoids that problem, but is syntactically heavyweight, and the interleaving of commas and semicolons is (IMHO) confusing.

Proposal: within constructor syntax only (at least for now, because I think it might be ambiguous in other contexts), allow the following:

[string-dict3: "a" => 1, "b" => 2, "c" => 3]

where x => y is simply the tuple {x; y}. The grammar rule would require that if you used this syntax on any of the pairs, you'd need to use it for all of them, so no intermixing of [string-dict-weird: "a" => 1, {"b"; 2}] allowed.

Oddly, to me at least, this sugar seems lighter weight and easier to type, despite objectively being the same exact number of characters...

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions