Dataphor icon indicating copy to clipboard operation
Dataphor copied to clipboard

feature - attribute names first in row literals

Open duncand opened this issue 8 years ago • 2 comments

Currently the only literal syntax D4 provides for row values is row { v1 name1, v2 name2, ... } while row type declarations have the format row { name1 : type1, name2 : type2, ... }.

I request a new feature such that D4 also supports having the attribute names on the left in row value literals as well, for example row { name1 : v1, name2 : v2, ... }.

Practically speaking, human readable data formats or source code representing name-value pairs are much easier to read when the names come first / on the left, especially when those may have multiple levels of nesting.

This feature would gain consistency with a majority of other languages and formats, including JSON and XML and C# and many others whose syntax for name-value pairs has the name first.

This feature would also boost internal consistency for D4 itself, such that the name comes first both in row literals and in row type declarations.

It appears that D4 already has a pattern to distinguish names on the left vs on the right, such that a colon is between the pair when it is on the left, while there is no colon when the name is on the right.

Given that, AFAIK, there isn't a lexical context where both a row literal and a type declaration could both appear, context should then tell the parser whether a row { foo : bar } is a row literal or a row type declaration. If that isn't the case, we could come up with another syntax to avoid ambiguity, but the key feature is that the name appears on the left.

Optionally, other areas of syntax that have the name on the right could also gain an alternative where it is on the left, but the row literals are the most important.

Thank you in advance.

duncand avatar Jul 03 '17 19:07 duncand

This is rather minor syntactic nitpick, but I guess it's worthwhile to change. I'd rather use = instead of : in a row expression. So the type of a row is { label : type, ... }, but the term of that type is { label = X }, where X is of type type.

ashalkhakov avatar Jul 21 '17 03:07 ashalkhakov

Well the main detail of importance as far as I'm concerned is that name-value pairs have the name on the left; what symbols if any go between them is of lesser concern. Aesthetically, I think using colons to separate all name value pairs of every kind that are declarational in nature is best. See also that colons are popular for this usage in a wide variety of languages, including AFAIK JSON, C#, Java, Python, Perl 6, and more; I believe colons are the single most popular defacto standard out there. Visually it also makes sense since a colon is a pair of dots which symbolizes a pair of things.

duncand avatar Jul 21 '17 04:07 duncand