digitalmars.D - Array-wise expressions
- Lobachevsky (8/8) Jan 06 2013 Is there any plan to extend array-wise expressions to include
- David Nadlinger (7/9) Jan 06 2013 Currently, there are no plans for adding a feature like this – at
- Xinok (8/16) Jan 06 2013 Performing this action would require several calls to foo. By
Is there any plan to extend array-wise expressions to include calls to arbitrary "scalar" functions, i.e. auto a = [1.2, 2.3, 3.4]; auto b = [7.1, 8.2, 9.3]; auto c = new double[3]; c[] = sin( 4 * a[] + b[] ); or c[] = foo(a[], b[], 42);
Jan 06 2013
On Sunday, 6 January 2013 at 15:39:03 UTC, Lobachevsky wrote:Is there any plan to extend array-wise expressions to include calls to arbitrary "scalar" functionsCurrently, there are no plans for adding a feature like this – at least I'm not aware of any. However, you can just use std.algorithm.map and write map!sin(…), possibly followed by .array() (import std.array) for eager evaluation. David
Jan 06 2013
On Sunday, 6 January 2013 at 15:39:03 UTC, Lobachevsky wrote:Is there any plan to extend array-wise expressions to include calls to arbitrary "scalar" functions, i.e. auto a = [1.2, 2.3, 3.4]; auto b = [7.1, 8.2, 9.3]; auto c = new double[3]; c[] = sin( 4 * a[] + b[] ); or c[] = foo(a[], b[], 42);Performing this action would require several calls to foo. By convention, array operations aren't loops; it only calculates the R-value once, then sets all elements to the same value. I wrote this as a quick example: http://dpaste.dzfl.pl/4ba03ef6 It does get a random value, but it only calls rand() once so all of the elements in the array are set to the same random value.
Jan 06 2013