in reply to Re^10: Better mousetrap (getting top N values from list X)
in thread Better mousetrap (getting top N values from list X)

Hmmm. Now you understand why I said "called but not used the comparator function" back up there somewhere. I could never get the values I was stacking to show up in the sub either?

I simplified things by moving all the GV stuff into the callComp() wrapper, which allows me to call the comparator sub without segfaults, but I still cannot access the values either via @_ or $a/$b?

int callComp( SV* cmp, SV *a, SV *b) { int count, rv; GV *first = gv_fetchpv("a", TRUE, SVt_PV); GV *second = gv_fetchpv("b", TRUE, SVt_PV); dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs( a ); XPUSHs( b ); PUTBACK; GvSV(first) = a; GvSV(second) = b; if( ( count = call_sv( cmp, G_SCALAR|G_NOARGS) ) != 1 ) croak( "Bad comparator" ); SPAGAIN; rv = POPi; FREETMPS; LEAVE; }

That said, when I look at what is done in the reduce() function in List::Util.xs, we are only scratching the surface yet. I've read perguts a dozen times over the last two days, but it's one of those documents that you have to experiment with each nuance of every sentance to understand the meaning and implications.

I was kind of hoping that Inline::C + perlapi would allow me to bypass the requirement for acquiring that understanding--but it seems not.

I'm not sure that I am interested in becoming an XS programmer. The only help available seems to be the p5p list--and they are all too busy doing, to be interested in teaching to do. Oh well!


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.