digitalmars.D - Thoughts on tuple indexing syntax...
- Chad J (36/36) Oct 09 2012 From what I read on the "DIP19: Remove comma operator..." thread it
From what I read on the "DIP19: Remove comma operator..." thread it sounded like one of the difficult challenges for tuples is ambiguities created by indexing tuple elements that might also be random access ranges (arrays). It gets especially nasty for single-element tuples. Would it help if we used something /besides/ the normal index notation for this? My immediate thoughts were something like: (int,float) a; a[[0]] = 1; a[[1]] = 1.0; But the idea of introducing the [[ and ]] tokens is probably not going to cut it. Next I thought of this: (int[]) a; a.[0] = new int[10]; a[0] = 1; assert(a.[0][0] == 1); Thus a trailing dot in paths with brackets would indicate tuple dereferencing. Another thought was to use a trailing sign for this: (int[]) a; a [0] = new int[10]; a[0] = 1; assert(a [0][0] == 1); In fact, I wonder if the extra brackets are necessary at all: (int[]) a; a.0 = new int[10]; a[0] = 1; assert(a.0[0] == 1); (int[]) a; a 0 = new int[10]; a[0] = 1; assert(a 0[0] == 1); Assuming I haven't missed some bad interactions with other syntax, then these notations should make tuple element access unambiguous. Does this help?
Oct 09 2012