Hi - On 9/4/16, 4:32 AM, "Russel Winder" <[email protected]> wrote:
> I suspect the best way is to do > what Python has done and allow a trailing comma in all places. > () empty tuple > (1,) single item tuple > (1, 2,) or (1, 2) two item tuple > > [] empty array > [1] or [1,] single item array > [1, 2] or [1, 2,] two item array > > There is a beautiful consistency here that Chapel, C++, Java, etc. have > missed. It makes manipulating data tables so much easier. I personally agree with you. I think you should raise the issue on chapel-developers (or chapel-users if you prefer) to see if there are objections. I doubt that it would be a difficult change to do, but it does involve changing the parser. Cheers, -michael On 9/4/16, 4:32 AM, "Russel Winder" <[email protected]> wrote: >On Sat, 2016-09-03 at 22:57 -0700, Paul Cassella wrote: >> Hello Russel, >> >> You're tripping over a syntactic wrinkle: a singleton tuple is >> written >> with a curious concluding comma, as in > >I shall rant a bit… > >> var onetuple = (1,); >> >> >> Without it, the parentheses are taken just for grouping. E.g., >> >> var justaone = (1); >> >> results in a variabe of type int, not 1*int. > >This is a problem that Python has had for decades, so this is an >entirely reasonable "get out", I even tried it and it worked >previously. However… > >> >> In your example below, when the first two 5-tuples are commented out >> there's only one left. So in order for testData to be a tuple >> containing >> just the one 5-tuple, it needs the trailing comma: >> >> const testData = ( ([0.0, 2.0, 2.0, 4.0], 2.0, 2.0, 1.0, >> sqrt(2.0)), ); >> >> Without it, the outer parens are used for normal grammatical grouping >> but >> otherwise ignored. That leaves testData being the 5-tuple itself. >> (Which, being non-homogeneous, can't be iterated over with a normal >> for >> loop. I gather having that for loop iterate over the elements of >> the >> 5-tuple wasn't your intent anyway.) > >…so the compiler needs to be fixed. I suspect the best way is to do >what Python has done and allow a trailing comma in all places. Yes I >know C++, Java, etc. do not allow this, but they are wrong. Python has >this right. > >() empty tuple >(1,) single item tuple >(1, 2,) or (1, 2) two item tuple > >[] empty array >[1] or [1,] single item array >[1, 2] or [1, 2,] two item array > >There is a beautiful consistency here that Chapel, C++, Java, etc. have >missed. It makes manipulating data tables so much easier. Having the >allowed trailing comma is trivial but it saves so much pain and >anguish. If you look at the data tables of any Python, Django, Pyramid, >etc. system (and Django and Pyramid have lots of these) they are a >relative joy to manipulate due to the consistency of every line ending >in a comma. The last one is redundant, but that is the joy of the >situation. > >In this, Chapel should do as Python does, not as C++ or Java does. > > >BTW is there a syntax for describing a n-tuple? there is 1-tuple, 2- >tuple, 3-tuple, etc. where the length is known but what about an n- >tuple for returning a tuple where the length is only definable at >runtime? I suspect this is not possible because the size function >return a param rather than a const. If true, this is very sad. > >The the question arises how to denote the return type of a function >that returns an array of length only determined at runtime? [?] real >for example just causes a compiler error as a return type. > >-- >Russel. >========================================================================== >=== >Dr Russel Winder t: +44 20 7585 2200 voip: >sip:[email protected] >41 Buckmaster Road m: +44 7770 465 077 xmpp: [email protected] >London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder ------------------------------------------------------------------------------ _______________________________________________ Chapel-bugs mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/chapel-bugs
