Hi, here's one that I have no idea how to go about:
Take this Perl code: my $i = iterator([1 .. 3]); while (defined (my $val = $i->()) { print $val, "\n"; } __END__ 1 2 3 I am now trying to implement iterator() as XSUB so its job is to return a closure (closing over iterator's argument). Ideally, the function reference it returns should also be implemented as XSUB. My idea was to get the CV* of the iterator to be returned, maybe thusly: CV *closure = get_cv("_iterator", FALSE); ... XSRETURN(sv_2mortal(newSVrv_noinc((SV*)closure))); A CV has a padlist so I thought I could simply abuse closure's padlist to store the array-ref passed to iterator(). And then, each time this iterator is triggered, the XSUB implementing it can access its own padlist and shift a value from the array-ref stored inside. So far I don't know whether the above is even theoretically feasible. I notice that CvPADLIST(closure) is null which is probably a bad sign. And then I have no idea how an XSUB could access its own padlist. It's not in PL_curpad as it looks. Or does someone know how to do this properly? The sketched outline above looks quick-and-dirty-ish (not evenin mentioning that does't yet work). Cheers, Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval