digitalmars.D.learn - dupping to allow vector operation?
- bearophile (15/15) Oct 09 2014 Observe:
 - John Colvin (4/19) Oct 09 2014 Why not? Looks fine to me, you've explicitly allocated some new
 - John Colvin (2/27) Oct 10 2014 To clarify: 4 is good, 3 and 5 are not.
 - "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (8/21) Oct 09 2014 It's equivalent to:
 - bearophile (4/11) Oct 09 2014 So do we need a new different syntax to do it? :-)
 
Observe:
void main() {
      int[3] a1 = [1, 3, 6];
      int[]  a2 = a1[] * 3;       // line 3, Error
      int[]  a3 = a1.dup[] *= 3;  // line 4, OK?
      int[]  a4 = (a1[] * 3).dup; // line 5, Error
}
Currently the operation in line 4 is accepted:
test.d(3,17): Error: array operation a1[] * 3 without destination 
memory not allowed
test.d(5,18): Error: array operation a1[] * 3 without destination 
memory not allowed
Is it a good idea to support something like line 5?
Bye,
bearophile
 Oct 09 2014
On Thursday, 9 October 2014 at 11:29:14 UTC, bearophile wrote:
 Observe:
 void main() {
      int[3] a1 = [1, 3, 6];
      int[]  a2 = a1[] * 3;       // line 3, Error
      int[]  a3 = a1.dup[] *= 3;  // line 4, OK?
      int[]  a4 = (a1[] * 3).dup; // line 5, Error
 }
 Currently the operation in line 4 is accepted:
 test.d(3,17): Error: array operation a1[] * 3 without 
 destination memory not allowed
 test.d(5,18): Error: array operation a1[] * 3 without 
 destination memory not allowed
 Is it a good idea to support something like line 5?
 Bye,
 bearophile
Why not? Looks fine to me, you've explicitly allocated some new 
memory for the result to sit in, the lack of which is the 
motivation for lines 3 an 5 being errors.
 Oct 09 2014
On Thursday, 9 October 2014 at 18:01:27 UTC, John Colvin wrote:On Thursday, 9 October 2014 at 11:29:14 UTC, bearophile wrote:To clarify: 4 is good, 3 and 5 are not.Observe: void main() { int[3] a1 = [1, 3, 6]; int[] a2 = a1[] * 3; // line 3, Error int[] a3 = a1.dup[] *= 3; // line 4, OK? int[] a4 = (a1[] * 3).dup; // line 5, Error } Currently the operation in line 4 is accepted: test.d(3,17): Error: array operation a1[] * 3 without destination memory not allowed test.d(5,18): Error: array operation a1[] * 3 without destination memory not allowed Is it a good idea to support something like line 5? Bye, bearophileWhy not? Looks fine to me, you've explicitly allocated some new memory for the result to sit in, the lack of which is the motivation for lines 3 an 5 being errors.
 Oct 10 2014
On Thursday, 9 October 2014 at 11:29:14 UTC, bearophile wrote:
 Observe:
 void main() {
      int[3] a1 = [1, 3, 6];
      int[]  a2 = a1[] * 3;       // line 3, Error
      int[]  a3 = a1.dup[] *= 3;  // line 4, OK?
      int[]  a4 = (a1[] * 3).dup; // line 5, Error
 }
 Currently the operation in line 4 is accepted:
 test.d(3,17): Error: array operation a1[] * 3 without 
 destination memory not allowed
 test.d(5,18): Error: array operation a1[] * 3 without 
 destination memory not allowed
 Is it a good idea to support something like line 5?
It's equivalent to:
     int[] tmp = a1[] * 3;
     int[] a4 = tmp.dup;
The first part is of course identical to line 3, so this should 
be an error, too. Normal rules for evaluation order require `a1[] 
* 3` to be evaluated before `(...).dup`, so where is it supposed 
to store the intermediate result?
 Oct 09 2014
Marc Schütz:
 It's equivalent to:
     int[] tmp = a1[] * 3;
     int[] a4 = tmp.dup;
 The first part is of course identical to line 3, so this should 
 be an error, too. Normal rules for evaluation order require 
 `a1[] * 3` to be evaluated before `(...).dup`, so where is it 
 supposed to store the intermediate result?
So do we need a new different syntax to do it? :-)
Bye,
bearophile
 Oct 09 2014








 
 
 
 "John Colvin" <john.loughran.colvin gmail.com> 