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<[email protected]>  wrote:
I said token, but I meant function. No Devel::Declare here.

On Jan 13, 2012 6:00 PM, "David Mertens"<[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"<[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

Reply via email to