Ralf Schelkle <ralf.schel...@gmx.de> wrote on 06/24/2010 06:30:40 PM:
> Hello x10 Team, > > I'm using x10 2.0.4 with the IDE Eclipse. > I'm realy confused why I get erros for following code: > > #1 public def func(){ > #2 shared var arr :Array[Double](101, 0..100); > #3 finish foreach ((i) in 0..100){ > #4 var x: Double = i * 2.0; > #5 arr(i) = x; > #6 arr.set(x, i); > #7 } > #8 } > > for line #5 I get the error: > "Cannot assign expression to array element of given type. Expression: x > Type: x10.lang.Double Array > element: arr(i) Type: x10.lang.Double" > > and for line #6 the error: > "Multiple messages at this line. > - Method set(v: x10.lang.Double, i0: > x10.lang.Int){x10.array.Array#this.region.rank==1}[] > in x10.array.Array[x10.lang.Double] cannot be called with arguments > (x10.lang.Double, x10.lang.Int > {self==i}); Call invalid; calling environment does not entail the > method guard. > - Method set(v: x10.lang.Double, i0: > x10.lang.Int){x10.array.Array#this.region.rank==1}[] > in x10.array.Array[x10.lang.Double] cannot be called with arguments > (x10.lang.Double, x10.lang.Int > {self==i}); Call invalid; calling environment does not entail the > method guard." > > What I read in the errors above is that both types are equal so I don't > get why this does not work. > > #5 and #6 should to exactly the same. The idea behind this code is to > create an array and save each value in this array to create the sum of > all calculations at the end (sum not included in this snippet). > My Problem is how can I access an array? Or what am I doing wrong here > in line #5 and #6 when I try to store a value in the array? Hi, You're right, at the moment lines #5 and #6 are the same semantically. The real error is the message from line #6 -- the one from line #5 desugars the error, and seems to be overzealous in doing that. Your problem is that you declared variable "arr" to be of type Array[Double](101, 0..100) in line #2. This has a few problems -- first off, there is no such type, so you should have gotten an error from the compiler about this. Second, the fact that you didn't indicate that your array is of rank 1 means that you cannot call the set() method with a single index (that's what the method guard really says). Also, since you're not actually reassigning arr in the foreach loop, you may as well make it a val. So, what you probably meant to say in line #2 was #2 val arr = new Array[Double](0..100); And then your code should simply work. It would be really helpful if you reported in JIRA the 3 problems you've encountered (the unreported error in line #2, the hard to understand error message in line #6, and the excessive desugaring of the error in line #5). We could then make sure that they are fixed in future releases. Thanks, Igor -- Igor Peshansky (note the spelling change!) IBM T.J. Watson Research Center X10: Parallel Productivity and Performance (http://x10-lang.org/) XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/) "I hear and I forget. I see and I remember. I do and I understand" -- Confucius ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ X10-users mailing list X10-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/x10-users