A little challenge...

Ary Borenszweig ary at esperanto.org.ar
Fri Feb 26 06:18:13 PST 2010


Norbert Nemec wrote:
> Hi everybody,
> 
> thinking about array expressions, I have stumbled over an interesting 
> challenge for which I still have no idea:
> 
> Consider the mathematical sum notation:
> 
>     \sum_i a_i*b_i
> 
> here, the variable i is defined only at the scope inside the expression.
> 
> A analogous D syntax could be something like
> 
>     sum!(i)(a[i]*b[i])
> 
> where sum would have to be some kind of template that takes i as a name 
> parameter and then defines it as variable inside the scope of the second 
> expression.

You are missing i's initial and ending values.

I think it should be something like:

sum!("i", 0, n)(a[i]*b[i])



More information about the Digitalmars-d mailing list