Ok so my previous implementation had some problems. I had been reinstalling PDL after a gut rehab of my perlbrew.
Anyway here is my implementation as a GitHub gist (pastebin + editing and javascript embedding). https://gist.github.com/1637872 Cheers, Joel On Wed, Jan 18, 2012 at 9:33 PM, Joel Berger <[email protected]>wrote: > Devel::Declare is a compile-time thing, so unless `eval`s have a compile > phase, I don't think that it will work in the pdl shell. > > Further, at least my implementation is very hueristic based. I'm sure it > could be made better. > > Anyway all that said, it should work just like the previous examples. Here > is a simple one: > > #!/usr/bin/env perl > > use strict; > use warnings; > > use Latest; > > my $pdl = xvals(7); > > my $where = $a->where(latest > 3); > > print $where > > On Wed, Jan 18, 2012 at 8:18 PM, chm <[email protected]> wrote: > >> Hi Joel- >> >> Do you have an example that shows this >> implementation working? Would this >> be something you load in the PDL shell? >> >> Thanks, >> Chris >> >> >> On 1/13/2012 7:45 PM, Joel Berger wrote: >> >>> A VERY naive D::D implementation: >>> >>> package Latest; >>> >>> use strict; >>> use warnings; >>> use Devel::Declare (); >>> >>> my $keyword = 'latest'; >>> >>> sub import { >>> my $class = shift; >>> >>> my $caller = caller; >>> >>> Devel::Declare->setup_for( >>> $caller, >>> { $keyword => { const => \&parser } } >>> ); >>> no strict 'refs'; >>> *{$caller.'::'.$keyword} = sub (@) {return @_}; >>> >>> } >>> >>> sub parser { >>> my $linestr = Devel::Declare::get_linestr; >>> >>> die "Too confusing" if do { >>> my @ops = $linestr =~ /(latest)/g; >>> @ops> 1; >>> }; >>> >>> if ($linestr =~ /(\$\w)->/) { >>> my $latest = $1; >>> $linestr =~ s/latest/latest $latest/; >>> warn "Rewritten: $linestr"; >>> Devel::Declare::set_linestr($**linestr); >>> } >>> } >>> >>> 1; >>> >>> On Fri, Jan 13, 2012 at 6:11 PM, David Mertens<dcmertens.perl@gmail.** >>> com <[email protected]>> wrote: >>> >>>> I said token, but I meant function. No Devel::Declare here. >>>> >>>> On Jan 13, 2012 6:00 PM, "David >>>> Mertens"<dcmertens.perl@gmail.**com<[email protected]>> >>>> wrote: >>>> >>>>> >>>>> Yeah, this should work, I think, though I would prefer the token last, >>>>> latest, or recent. We would obviously have to be careful about >>>>> exporting >>>>> such a basic token. We would do something like >>>>> >>>>> use PDL::Latest; >>>>> $a->mv(0,-1)->rotate(3)->**where(latest> 3); >>>>> no PDL::Latest; >>>>> >>>>> The method would return the last piddle modified, which itself could be >>>>> >>>> >>> stored in the package global $PDL::last_modified_piddle. This gives >>>>> function >>>>> authors control over the "latest" behavior of their functions. It >>>>> would also >>>>> require that all current PDL functions would need to be retrofitted >>>>> with >>>>> this behavior. >>>>> >>>>> This short example seems like overkill, but in larger cases, or cases >>>>> in >>>>> which the user doesn't have conflicts, it would be nice. >>>>> >>>>> David >>>>> >>>>> On Jan 13, 2012 5:35 PM, "Chris >>>>> Marshall"<devel.chm.01@gmail.**com<[email protected]>> >>>>> wrote: >>>>> >>>>>> >>>>>> A source filter would be the simplest. Maybe another >>>>>> clever way could be found, perhaps have the self() set >>>>>> from the pdl output of the previous PDL method call or >>>>>> routine. >>>>>> >>>>>> --Chris >>>>>> >>>>>> On Fri, Jan 13, 2012 at 2:57 PM, Joel Berger<[email protected]* >>>>>> *> >>>>>> >>>>> >>> wrote: >>>>>> >>>>>>> $a->mv(0,-1)->rotate(3)->**where(self>3) >>>>>>>> >>>>>>> >>>>>>> How on earth would you do that? Perhaps with a source filter, but >>>>>>> unless you were going to make singleton objects I can't think of how >>>>>>> >>>>>> >>> one would implement that. >>>>>>> >>>>>>> Joel >>>>>>> >>>>>> >
_______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
