Re: problem with reduce on array of Tuples

2010-05-27 Thread Pelle

This has nothing to do with the tuples, I think.

test2.d:

import std.algorithm;

void main() {
map!((int x){return x+1;})([1,2,3,4,5]);
}

pp ~/dee% rdmd test2.d
test2.d(4): Error: delegate std.algorithm.__dgliteral1 cannot access 
frame of function __dgliteral1

test2.d(4): Error: template instance test2.main.map!(delegate int(int x)
{
return x + 1;
}
) error instantiating


It's a bug with the delegate literals inside the template.


problem with reduce on array of Tuples

2010-05-27 Thread Adrian Matoga
The following code fails to compile:

double sim(Document doc, string query)
{
alias Tuple!(double, "wij", double, "wiq") Weights;
Document q = Document.fromString(query);
Weights[] wi;
foreach (s; StrFilt(query))
wi ~= Weights(doc.termFreq(s) * invDocFreq(s), q.termFreq
(s) * invDocFreq(s));
return
reduce!((double acc, Weights w) { return acc + 0; /*w.wij
* w.wiq;*/ })(0.0, wi) /
(sqrt(reduce!((double acc, Weights w) { return acc + 0; /
*sqr(w.wij);*/ })(0.0, wi) *
 sqrt(reduce!((double acc, Weights w) { return acc + 0; /
*sqr(w.wiq);*/ }(0.0, wi);
}

and DMD 2.046 shows the following messages:
ir.d(119): Error: delegate std.algorithm.__dgliteral3 cannot access
frame of fun
ction __dgliteral3
ir.d(232): Error: template instance ir.Index.sim.Reduce!(delegate
double(double
acc, Tuple!(double,"wij",double,"wiq") w)
{
return acc + 0;
}
) error instantiating
ir.d(119):instantiated from here: reduce!(delegate double
(double acc, Tu
ple!(double,"wij",double,"wiq") w)
{
return acc + 0;
}
)


Is it my fault because of some misunderstanding or other error, or
should I report it as a bug in compiler/library?
The same function compiled well with reduce on StrFilt(query) instead
of Weights.

I attach the full source.
begin 644 ir.d
M:6UP;W)T('-T9"YS=&1I;SL-"FEM<&]R="!S=&0N65S(BP@(FYO(BP@(FYO="(L(")B=70B
M+"`B:70B+"`B:6XB+"`B:2(L(")Y;W4B+"`B:&4B+"`BR!R971UPT*"7-T$9R97$[#0H)#0H)=F]I9"!A9&1,:6YE*'-TPT*"0D)*RMF$9R97$H*0T*"7L-
M"@D);6%X1G)E<2`](&UI;E!O%MK97E=('X]
M(&1O8SL-"@D)?0T*"7T-"@D-"@ED;W5B;&4@:6YV1&]C1G)E<2AS=')I;F<@
M=&5R;2D-"@E[#0H)"6EF("AT97)M("%I;B!I;F1E>"D-"@D)"7)E='5R;B`P
M.PT*"0ER971UR!R971U2D-"@E[#0H)
M"61O=6)L95M$;V-U;65N=%T@PT*"0EW