John Porter wrote:
> Larry Wall wrote:
> > We do have to worry about the C<next> loop control function though.
> > It's possible that in
> >
> >     FOO: while (1) {
> >     next FOO if /foo/;
> >     ...
> >     }
> >
> > the C<FOO> label is actually being recognized as a pseudo-package
> > name!  The loop could well be an object whose full name is
> C<MY::FOO>.
> > Or something like that.  But maybe that's a gross hack.  Seems a bit
> > odd to overload C<next> like that.  Maybe we need a different word.
>
> Pardon me if someone has already suggested this, but...
> Couldn't labels really be (aliases to) iterator objects?
> So that
>       next FOO
> really *does* mean
>       FOO.next

This thread suggests a need to address the reflection capabilities
of Perl6. Looking through the Camel book, I can't see which
apocalypse this would be in, so perhaps now's a good time :).

The trick used above seems like a good thing but, to do it properly,
we would need a complete model of how a perl program views itself,
both statically and dynamically.

Ideally I would like to see a full MOP for Perl6; and perhaps an
AspectPerl module analagous to AspectJ from the AOP folks.

If labeled blocks are objects, should they be mutable? Is self-
modifying code acceptable?


  my $a = 1;
  $counter = sub {
    COUNT: { ++$a }
    print "count=$a"
  }
  &$counter(); # count=2
  &$counter.COUNT();
  &$counter(); # count=4
  $counter.COUNT = sub { --$a }
  &$counter(); # count=3
  $counter.statement[-1].args{fh} = $STDERR;
  &$counter(); # prints count=2 on stderr

  print "current code is: ", $counter.COUNT.pretty_print;


Of course, the thing that is labeled would effect what methods exist. Labels
that don't refer to blocks would have fewer capabilities than those that do;
and those that refer to loops might provide all sorts of wierd things.

I would expect these Reflection objects to allow me to navigate the source
code (and modify it); and also navigate to the current instances of
execution. A subroutine should have a method that returns a collection
of all the current execution contexts that are in it. There'a a fair amount
that a debugger module can do, but the general capability is more than
just debugging.

Interaction with the optimizer would be hours of fun for all the family!


Dave.
--
Dave Whipp, Senior Verification Engineer,
Fast-Chip inc., 950 Kifer Rd, Sunnyvale, CA. 94086
tel: 408 523 8071; http://www.fast-chip.com
Opinions my own; statements of fact may be in error.

Reply via email to