A little challenge...

Norbert Nemec Norbert at Nemec-online.de
Sat Feb 27 01:56:00 PST 2010

Robert Jacques wrote:
> That sounds sensible. However, extensive experience in Matlab has taught 
> me that resorting to custom for-loop indicates you've failed to 
> sufficiently think in arrays. :)

Indeed, most use cases are simple enough to be handled in array 
notation. I have worked with Matlab and Python and managed to come up 
with array notations in many non-trivial cases as well. However, once in 
a while, it just cannot be done. Typically, this happens when you have 
to handle non-linear terms or high order tensorial objects.

Of course, my examples were simple enough to permit alternative 
expressions, but I have encountered quite a number of cases where
I could not avoid a loop in Python. I is hard to spontaneously construct 
something useful that I can describe in a few lines.

Imagine a charge density in one dimension:
and then compute the coulomb energy

Or an expression containing function calls


Ultimately, 'sum' and other reduction would actually be just one use 
case. One could even use the same mechanism to construct arrays from 

	auto A = array(a=0:10,b=0:20)(2*a + b%3)

(Disregard the exact syntax here...)

I will think further about this and try to come up with more specific 
use cases.


More information about the Digitalmars-d mailing list