Ranges and Algorithms -- Templates, Delegates, or Ranges?

Mafi mafi at example.org
Tue Feb 22 03:15:55 PST 2011


Am 22.02.2011 11:29, schrieb %u:
> Having learned functional programming in Scheme a couple months ago, I tried my hand at using map(), reduce(), and filter() in D:
>
>      int addend = 5;
>      map(delegate int(int x) { return x + addend; }, iota(1, 5));
>
> but it didn't work. It turned out that map() actually took the mapper as its _template_ argument, not as a function argument. Not too much of
> a problem, it probably seemed to be...
> except that it's a critical problem. It makes map(), reduce(), filter(), etc. to become 10x less useful, because there's no way to change
> their behavior at runtime, depending on program's state.
>

I did never try and so I'm unsure but shouldn't you be able to give a 
delegate variable as template parameter.
std.algorithms.map's parameter is an alias parameter so it should be 
able alias your variable and use it's runtime value.
If it does not work this way it's a bug IMO.

Mafi



More information about the Digitalmars-d mailing list