On Fri, 30 Jul 2010 12:19:16 -0500 "Patrick R. Michaud" <pmich...@pobox.com> wrote:
PRM> On Fri, Jul 30, 2010 at 09:17:30AM -0500, Ted Zlatanov wrote: >> I have a Perl 5 module called Every which provides, simply, >> >> every(5); # true on invocation 5, 10, etc. >> every(seconds => 5); # true at 5, 10, etc. seconds >> >> It's really nice in endless loops, logging, etc. I'd like to translate >> it to Perl 6 (using Rakudo specifically). >> >> Its current implementation requires Devel::Opcode because it needs to >> know what location is getting called again and again. >> >> Generally for Perl 6, is there a simple way to make Every obsolete by >> using built-ins? I'd love that but haven't seen anything in the >> language that would help. PRM> I suspect something like CALLER::<$?FILE> and CALLER::<$?LINE> might PRM> eventually do what you want -- they would at least get to a unique PRM> line within the calling. CALLER:: and $?FILE and $?LINE are not PRM> yet implemented in Rakudo, but I suspect the language specification PRM> has sufficient features to eventually make a clean implementation a PRM> possibility. (also suggested by Moritz with state variables as the real solution) I could have used __LINE__ in Perl 5 as well but chose not to so multiple calls to every() could be made on the same line. I'd like to provide the same functionality in Rakudo. So state variables seem like the easiest solution outside of the core and I can wait until they are available. If anyone thinks every() could go in the core or really wants to see it ported sooner let me know :) Thanks Ted