Hi Chapel Developers --
Twice in the past month, someone has been caught by the following issue.
They write code like this:
for i in [1..10] do
foo(i);
thinking that they are iterating over the values 1..10 and i will be an
integer, when in fact they've created a 1-element array of ranges and i is
a range (and then foo() is called in a promoted manner, assuming it was
expecting an integer).
I've been thinking that perhaps to mimic the 1-tuple syntax, we should
require 1-element array literals to use a trailing comma as well such that
the above would be a syntax error and the correct form (if it's what you
really wanted) would be:
for i in [1..10, ] do
foo(i);
It seems like most array literals that are actually interesting probably
have multiple elements, so for most use cases, this wouldn't have much of
an impact. It also seems that this would be more symmetric with what we
do for tuples.
And finally, it *may* clean up the parser given that the other form of
square brackets is the compact forall loop notation. I.e.,
[i in 1..10] i => forall i in 1..10 do
I believe we get into lots of complexity in the compiler because these two
cases can be mistaken for one another, so it may be that by distinguishing
them ("array literals always have commas") the parser will become more
manageable.
Thoughts?
-Brad
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers