Re: Is [] mandatory for array operations?

2010-05-13 Thread Bruno Medeiros
On 04/05/2010 21:19, Andrei Alexandrescu wrote: Walter Bright wrote: Don wrote: Walter Bright wrote: Don wrote: There are several compiler bugs relating to array operations, and almost all relate to this issue. I'd like to fix them, but I need to know which way it is supposed to work. The [

Re: Is [] mandatory for array operations?

2010-05-09 Thread Pelle
On 05/09/2010 04:21 PM, bearophile wrote: Pelle: Please, no. :) Just require @property for assignment-is-a-call code. Special cases are bd. They are usually not special enough. Experience shows me that implicit operations or untidy semantics often leads to big troubles, even when you don

Re: Is [] mandatory for array operations?

2010-05-09 Thread bearophile
Pelle: > Please, no. :) > Just require @property for assignment-is-a-call code. Special cases are bd. They are usually not special enough. Experience shows me that implicit operations or untidy semantics often leads to big troubles, even when you don't see such troubles at first. The obliga

Re: Is [] mandatory for array operations?

2010-05-09 Thread Pelle
On 05/04/2010 10:19 PM, Andrei Alexandrescu wrote: In the same vein, probably it's time to bite the bullet and require @property for parens-less function calls. Andrei Please, no. :) Just require @property for assignment-is-a-call code. //requires @property foo.x = 3; //does not require @pr

Re: Is [] mandatory for array operations?

2010-05-08 Thread Don
bearophile wrote: Johan Granberg: I think it is an acceptable tradeof that the people that need optimal speed write there code in a more uncompressed formm using manual loops or wathewer. Then the cases not on the criitical path of the program can be written more compactly using a slightly slowe

Re: Is [] mandatory for array operations?

2010-05-08 Thread bearophile
Johan Granberg: > I think it is an > acceptable tradeof that the people that need optimal speed write there code > in a more uncompressed formm using manual loops or wathewer. Then the cases > not on the criitical path of the program can be written more compactly > using a slightly slower but much

Re: Is [] mandatory for array operations?

2010-05-07 Thread Kagamin
Robert Jacques Wrote: > On Fri, 07 May 2010 09:52:46 -0400, Robert Jacques > wrote: > > Given that y[] is really syntactic sugar y[0..$], one option would be to > > bite the bullet an make [] a dedicated array op/vectorize operator. This > > would pave the way for using array ops with user

Re: Is [] mandatory for array operations?

2010-05-07 Thread Robert Jacques
On Fri, 07 May 2010 13:18:04 -0400, Kagamin wrote: Michel Fortin Wrote: There is some elegance to that solution since it chooses the right solution for the problem at hand. If you assign the result to a temporary array as above, it's probably because you'll need it somewhere else and thus you

Re: Is [] mandatory for array operations?

2010-05-07 Thread Robert Jacques
On Fri, 07 May 2010 11:44:18 -0400, Steven Schveighoffer wrote: On Fri, 07 May 2010 11:18:37 -0400, Robert Jacques wrote: On Fri, 07 May 2010 11:11:47 -0400, Steven Schveighoffer wrote: As I've said before, I think a possible compromise to this is to allow paren-less function calls

Re: Is [] mandatory for array operations?

2010-05-07 Thread Johan Granberg
Kagamin wrote: > Johan Granberg Wrote: > >> There is another use for array ops as well, that is to create a nice >> syntax for doing the same operation over all elements in an array. Matlab >> is doing this in a very nice way and it is far from all uses that >> requiers optimal speed. > > I actu

Re: Is [] mandatory for array operations?

2010-05-07 Thread Kagamin
Michel Fortin Wrote: > There is some elegance to that solution since it chooses the right > solution for the problem at hand. If you assign the result to a > temporary array as above, it's probably because you'll need it > somewhere else and thus you really need to keep the temporary around. >

Re: Is [] mandatory for array operations?

2010-05-07 Thread Kagamin
Johan Granberg Wrote: > There is another use for array ops as well, that is to create a nice syntax > for doing the same operation over all elements in an array. Matlab is doing > this in a very nice way and it is far from all uses that requiers optimal > speed. I actually saw butthurt about mat

Re: Is [] mandatory for array operations?

2010-05-07 Thread Steven Schveighoffer
On Fri, 07 May 2010 11:18:37 -0400, Robert Jacques wrote: On Fri, 07 May 2010 11:11:47 -0400, Steven Schveighoffer wrote: As I've said before, I think a possible compromise to this is to allow paren-less function calls when the return type is void. These functions cannot be misinterp

Re: Is [] mandatory for array operations?

2010-05-07 Thread Robert Jacques
On Fri, 07 May 2010 11:11:47 -0400, Steven Schveighoffer wrote: On Fri, 07 May 2010 10:08:22 -0400, Robert Jacques wrote: On Tue, 04 May 2010 16:19:09 -0400, Andrei Alexandrescu wrote: Walter Bright wrote: Don wrote: Walter Bright wrote: Don wrote: There are several compiler bugs

Re: Is [] mandatory for array operations?

2010-05-07 Thread Robert Jacques
On Fri, 07 May 2010 09:52:46 -0400, Robert Jacques wrote: Given that y[] is really syntactic sugar y[0..$], one option would be to bite the bullet an make [] a dedicated array op/vectorize operator. This would pave the way for using array ops with user defined types (e.g. matrices and rang

Re: Is [] mandatory for array operations?

2010-05-07 Thread Steven Schveighoffer
On Fri, 07 May 2010 10:08:22 -0400, Robert Jacques wrote: On Tue, 04 May 2010 16:19:09 -0400, Andrei Alexandrescu wrote: Walter Bright wrote: Don wrote: Walter Bright wrote: Don wrote: There are several compiler bugs relating to array operations, and almost all relate to this issue.

Re: Is [] mandatory for array operations?

2010-05-07 Thread Michel Fortin
On 2010-05-07 09:52:46 -0400, "Robert Jacques" said: On Fri, 07 May 2010 07:51:11 -0400, Michel Fortin wrote: On 2010-05-07 01:34:39 -0400, "Robert Jacques" said: And then there's the ambiguous case: x[] = foo(y[]); Which is an example of x[] = y; vs x[] = y[]; problem. True. The pro

Re: Is [] mandatory for array operations?

2010-05-07 Thread Robert Jacques
On Tue, 04 May 2010 16:19:09 -0400, Andrei Alexandrescu wrote: Walter Bright wrote: Don wrote: Walter Bright wrote: Don wrote: There are several compiler bugs relating to array operations, and almost all relate to this issue. I'd like to fix them, but I need to know which way it is sup

Re: Is [] mandatory for array operations?

2010-05-07 Thread Robert Jacques
On Fri, 07 May 2010 07:51:11 -0400, Michel Fortin wrote: On 2010-05-07 01:34:39 -0400, "Robert Jacques" said: On Fri, 07 May 2010 00:13:04 -0400, Jason House wrote: Robert Jacques Wrote: given real foo(real value) {...} and real[] foo(real[] value) {...} what should happen with the f

Re: Is [] mandatory for array operations?

2010-05-07 Thread Michel Fortin
On 2010-05-07 01:34:39 -0400, "Robert Jacques" said: On Fri, 07 May 2010 00:13:04 -0400, Jason House wrote: Robert Jacques Wrote: given real foo(real value) {...} and real[] foo(real[] value) {...} what should happen with the follow line of code: x[] = foo(y[]) + z[]; That can be interp

Re: Is [] mandatory for array operations?

2010-05-06 Thread Robert Jacques
On Fri, 07 May 2010 00:13:04 -0400, Jason House wrote: Robert Jacques Wrote: given real foo(real value) {...} and real[] foo(real[] value) {...} what should happen with the follow line of code: x[] = foo(y[]) + z[]; That can be interpreted in either of the following ways: foreach(i) x[i]

Re: Is [] mandatory for array operations?

2010-05-06 Thread Jason House
Robert Jacques Wrote: > On Thu, 06 May 2010 22:46:42 -0400, Michel Fortin > wrote: > > > On 2010-05-06 21:48:09 -0400, "Robert Jacques" said: > > > >> On Thu, 06 May 2010 20:57:07 -0400, Michel Fortin > >> wrote: > >> > >>> On 2010-05-06 19:02:03 -0400, Jason House > >>> said: > >>> >

Re: Is [] mandatory for array operations?

2010-05-06 Thread Robert Jacques
On Thu, 06 May 2010 22:46:42 -0400, Michel Fortin wrote: On 2010-05-06 21:48:09 -0400, "Robert Jacques" said: On Thu, 06 May 2010 20:57:07 -0400, Michel Fortin wrote: On 2010-05-06 19:02:03 -0400, Jason House said: Don Wrote: x[] = sin(y[]); I strongly favor the first synta

Re: Is [] mandatory for array operations?

2010-05-06 Thread Michel Fortin
On 2010-05-06 22:46:42 -0400, Michel Fortin said: That said, I'd expect the compiler to call sin(y) only once, so it'd be more like that: auto sinY = sin(y); for(int i = 0; i < x.length; i++) { x[i] = sinY[i]; } And I'd expect that because in the expr

Re: Is [] mandatory for array operations?

2010-05-06 Thread Michel Fortin
On 2010-05-06 21:48:09 -0400, "Robert Jacques" said: On Thu, 06 May 2010 20:57:07 -0400, Michel Fortin wrote: On 2010-05-06 19:02:03 -0400, Jason House said: Don Wrote: x[] = sin(y[]); I strongly favor the first syntax since it matches how I'd write it in a for loop. i.e. I'd re

Re: Is [] mandatory for array operations?

2010-05-06 Thread Robert Jacques
On Thu, 06 May 2010 20:57:07 -0400, Michel Fortin wrote: On 2010-05-06 19:02:03 -0400, Jason House said: Don Wrote: x[] = sin(y[]); I strongly favor the first syntax since it matches how I'd write it in a for loop. i.e. I'd replace [] with [i]. This is the best way to see array

Re: Is [] mandatory for array operations?

2010-05-06 Thread Michel Fortin
On 2010-05-06 19:02:03 -0400, Jason House said: Don Wrote: x[] = sin(y[]); I strongly favor the first syntax since it matches how I'd write it in a for loop. i.e. I'd replace [] with [i]. This is the best way to see array operations I've read up to now: replace [] with [i], i being th

Re: Is [] mandatory for array operations?

2010-05-06 Thread Robert Jacques
On Thu, 06 May 2010 19:02:03 -0400, Jason House wrote: Don Wrote: Walter Bright wrote: > Don wrote: >> Walter Bright wrote: >>> Don wrote: There are several compiler bugs relating to array operations, and almost all relate to this issue. I'd like to fix them, but I need to

Re: Is [] mandatory for array operations?

2010-05-06 Thread Jason House
Don Wrote: > Walter Bright wrote: > > Don wrote: > >> Walter Bright wrote: > >>> Don wrote: > There are several compiler bugs relating to array operations, and > almost all relate to this issue. I'd like to fix them, but I need to > know which way it is supposed to work. > >>> > >

Re: Is [] mandatory for array operations?

2010-05-06 Thread bearophile
Robert Jacques: > Do you have some specific examples in mind? I have tons of specific examples in mind :-) I have written some things here, and I'd like to write one more time about this: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=87311 http://www.digita

Re: Is [] mandatory for array operations?

2010-05-06 Thread Robert Jacques
On Thu, 06 May 2010 16:54:48 -0400, bearophile wrote: Johan Granberg: Matlab is doing this in a very nice way and it is far from all uses that requiers optimal speed. Some parts of the Chapel language are exceptionally well designed, and deserve to be stolen. For numerical computations

Re: Is [] mandatory for array operations?

2010-05-06 Thread Robert Jacques
On Thu, 06 May 2010 16:48:30 -0400, Don wrote: Robert Jacques wrote: On Thu, 06 May 2010 14:40:17 -0400, bearophile wrote: Kagamin: Since sin's result is not an array,< I am not sure, but I presume here Don was talking about a dispatch of the sin to all items of an array, so its result

Re: Is [] mandatory for array operations?

2010-05-06 Thread bearophile
Johan Granberg: > Matlab is doing > this in a very nice way and it is far from all uses that requiers optimal > speed. Some parts of the Chapel language are exceptionally well designed, and deserve to be stolen. For numerical computations it looks far better than Fortress. Bye, bearophile

Re: Is [] mandatory for array operations?

2010-05-06 Thread Don
Robert Jacques wrote: On Thu, 06 May 2010 14:40:17 -0400, bearophile wrote: Kagamin: Since sin's result is not an array,< I am not sure, but I presume here Don was talking about a dispatch of the sin to all items of an array, so its result is another (new or mutated in place) array. Bye,

Re: Is [] mandatory for array operations?

2010-05-06 Thread Johan Granberg
Robert Jacques wrote: > On Thu, 06 May 2010 14:40:17 -0400, bearophile > wrote: >> Kagamin: >>> Since sin's result is not an array,< >> >> I am not sure, but I presume here Don was talking about a dispatch of >> the sin to all items of an array, so its result is another (new or >> mutated in plac

Re: Is [] mandatory for array operations?

2010-05-06 Thread Robert Jacques
On Thu, 06 May 2010 14:40:17 -0400, bearophile wrote: Kagamin: Since sin's result is not an array,< I am not sure, but I presume here Don was talking about a dispatch of the sin to all items of an array, so its result is another (new or mutated in place) array. Bye, bearophile That

Re: Is [] mandatory for array operations?

2010-05-06 Thread bearophile
Kagamin: >Since sin's result is not an array,< I am not sure, but I presume here Don was talking about a dispatch of the sin to all items of an array, so its result is another (new or mutated in place) array. Bye, bearophile

Re: Is [] mandatory for array operations?

2010-05-06 Thread Kagamin
Don Wrote: > Two questions. (1) What happens with functions? For example: > x[] = sin(y[]); > OR > x[] = sin(y[])[]; > Array op is effectively a statement-wide operation (it can be even deemed as a statement itself), braces are the hint which arrays are iterated. Since sin's result is not an ar

Re: Is [] mandatory for array operations?

2010-05-04 Thread Bernard Helyer
On 05/05/10 08:19, Andrei Alexandrescu wrote: In the same vein, probably it's time to bite the bullet and require @property for parens-less function calls. Andrei Agreed. Is there any word on rewriting things like `fooInstance.prop += 3` for @properties?

Re: Is [] mandatory for array operations?

2010-05-04 Thread Andrei Alexandrescu
Walter Bright wrote: Don wrote: Walter Bright wrote: Don wrote: There are several compiler bugs relating to array operations, and almost all relate to this issue. I'd like to fix them, but I need to know which way it is supposed to work. The [] should be required. I worry that otherwise the

Re: Is [] mandatory for array operations?

2010-05-04 Thread Don
Walter Bright wrote: Don wrote: Walter Bright wrote: Don wrote: There are several compiler bugs relating to array operations, and almost all relate to this issue. I'd like to fix them, but I need to know which way it is supposed to work. The [] should be required. I worry that otherwise the

Re: Is [] mandatory for array operations?

2010-05-04 Thread Walter Bright
Don wrote: Walter Bright wrote: Don wrote: There are several compiler bugs relating to array operations, and almost all relate to this issue. I'd like to fix them, but I need to know which way it is supposed to work. The [] should be required. I worry that otherwise there will be ambiguous

Re: Is [] mandatory for array operations?

2010-05-04 Thread Trass3r
int[3] x, y; x[] = y * 2; // should work, but currently fails Don't know if this would cause any compiler problems but y could also be a scalar value. So requiring the [] would at least be unambiguous to the programmer. Hmm, maybe if you have two variables named very similarly and you mistyp

Re: Is [] mandatory for array operations?

2010-05-04 Thread Don
Walter Bright wrote: Don wrote: There are several compiler bugs relating to array operations, and almost all relate to this issue. I'd like to fix them, but I need to know which way it is supposed to work. The [] should be required. I worry that otherwise there will be ambiguous cases that w

Re: Is [] mandatory for array operations?

2010-05-04 Thread Walter Bright
Don wrote: There are several compiler bugs relating to array operations, and almost all relate to this issue. I'd like to fix them, but I need to know which way it is supposed to work. The [] should be required. I worry that otherwise there will be ambiguous cases that will cause trouble.

Is [] mandatory for array operations?

2010-05-04 Thread Don
According to my reading of the spec, array operations only require [] after the lvalue, not after any of the rvalues. So this should work: int[3] x, y; x[] = y * 2; // should work, but currently fails But in DMD at present, array operations only work if you write [] after _every_ array. x[] =