Hello Russel,

You're tripping over a syntactic wrinkle: a singleton tuple is written 
with a curious concluding comma, as in

  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.


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.)


-- 
Paul Cassella


On Sat, 3 Sep 2016, Russel Winder wrote:

> The code:
> 
>     const testData = (
>                       //([0.0, 2.0], 1.0, 1.0, 1.0, sqrt(2.0)),
>                       //([0.0, 2.0, 4.0], 2.0, 2.0, 1.0, sqrt(2.0)),
>                       ([0.0, 2.0, 2.0, 4.0], 2.0, 2.0, 1.0, sqrt(2.0))
>                       );
> 
>     proc main() {
>       for item in testData {}
>     }
> 
> 
> fails to compile with the message:
> 
> test_statistics.chpl:7: In function 'main':
> test_statistics.chpl:8: error: Cannot iterate over non-homogeneous tuples. If 
> you intended to use zippered iteration, add the new keyword 'zip' before the 
> tuple of iteratable expressions.
> 
> 
> If the tuples that are commented are uncommented then the code compiles
> fine.
> 
> 
------------------------------------------------------------------------------
_______________________________________________
Chapel-bugs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-bugs

Reply via email to