List Info

Thread: Re: introspection (and Perl 6)




Re: introspection (and Perl 6)
country flaguser name
United Kingdom
2008-01-20 14:04:14
--- jesse <jessefsck.com> wrote:

 > > features as any other modern programming
language.
> > 
> > *cough*introspection*cough* 
> 
> You can certainly introspect Perl, if you're willing to
sweet-talk
> her enough.

Introspection isn't build into Perl is, at best, heuristic
in nature.
You can take a look inside namespaces, but that's only part
of it.  For
example:

  my $method = $class->can('foo');
 
There are several problems with that (some of which the
current Perl 6
specification shares).  With the following code:

  if ( my $method = $class->can('foo') ) {
      my $hashref = $class->$method($arrayref);
  }

You have no way of knowing:

  1.  If that's a method or a function.
  2.  If that's a class or an instance method.
  3.  If it really returns a hash reference.
  4.  The number and type of arguments it accepts.

So let's say you have this:

  package My::Class;
  use HTML::Entities 'encode_entities';

With that code, My::Class->can('encode_entities') returns
a reference
to the encode_entities subroutine.  You can't call it like a
method,
nor can you determine its signature.  Perl's introspective
capabilities
are virtually non-existent.

Of course, if we don't ignore AUTOLOAD, then we're faced
with the
problem of needing to override 'can' ...

The fact that Perl 6's introspection model is also broken is
also
worrisome for me (http://www.perl
cabal.org/syn/S12.html):

  if my $method = $class.^can('foo') {
      ...
  }

Now we at least are guaranteed that it's a method, but none
of the
other problems are solved (actually, the class versus
instance one
might, but I can't tell from the docs).  Meta-programming
seems broken
in Perl 6 :(

Cheers,
Ovid

--
Buy the book  - http://www.or
eilly.com/catalog/perlhks/
Perl and CGI  - http://u
sers.easystreet.com/ovid/cgi_course/
Personal blog - http://publiu
s-ovidius.livejournal.com/
Tech blog     - http://use.perl.or
g/~Ovid/journal/

Re: introspection (and Glen Moray)
country flaguser name
United Kingdom
2008-01-20 15:50:02
--- Ovid <publiustemp-bondpmyahoo.com> wrote:

> Introspection isn't build into Perl is, at best,
heuristic in nature.
> You can take a look inside namespaces, but that's only
part of it. 
> For example:

Ah, sheesh.  Can we try and pretend all of these typos
aren't there? 
And I thought Glen Moray was my friend ...

Cheers,
Ovid

--
Buy the book  - http://www.or
eilly.com/catalog/perlhks/
Perl and CGI  - http://u
sers.easystreet.com/ovid/cgi_course/
Personal blog - http://publiu
s-ovidius.livejournal.com/
Tech blog     - http://use.perl.or
g/~Ovid/journal/

Re: introspection (and Perl 6)
user name
2008-01-21 10:14:57
$class.^can('foo')

That syntax is nearly as elegant as mud is not. :P


On Jan 20, 2008 3:04 PM, Ovid <publiustemp-bondpmyahoo.com> wrote:
> --- jesse <jessefsck.com> wrote:
>
>  > > features as any other modern programming
language.
> > >
> > > *cough*introspection*cough* 
> >
> > You can certainly introspect Perl, if you're
willing to sweet-talk
> > her enough.
>
> Introspection isn't build into Perl is, at best,
heuristic in nature.
> You can take a look inside namespaces, but that's only
part of it.  For
> example:
>
>   my $method = $class->can('foo');
>
> There are several problems with that (some of which the
current Perl 6
> specification shares).  With the following code:
>
>   if ( my $method = $class->can('foo') ) {
>       my $hashref = $class->$method($arrayref);
>   }
>
> You have no way of knowing:
>
>   1.  If that's a method or a function.
>   2.  If that's a class or an instance method.
>   3.  If it really returns a hash reference.
>   4.  The number and type of arguments it accepts.
>
> So let's say you have this:
>
>   package My::Class;
>   use HTML::Entities 'encode_entities';
>
> With that code, My::Class->can('encode_entities')
returns a reference
> to the encode_entities subroutine.  You can't call it
like a method,
> nor can you determine its signature.  Perl's
introspective capabilities
> are virtually non-existent.
>
> Of course, if we don't ignore AUTOLOAD, then we're
faced with the
> problem of needing to override 'can' ...
>
> The fact that Perl 6's introspection model is also
broken is also
> worrisome for me (http://www.perl
cabal.org/syn/S12.html):
>
>   if my $method = $class.^can('foo') {
>       ...
>   }
>
> Now we at least are guaranteed that it's a method, but
none of the
> other problems are solved (actually, the class versus
instance one
> might, but I can't tell from the docs). 
Meta-programming seems broken
> in Perl 6 :(
>
> Cheers,
> Ovid
>
> --
> Buy the book  - http://www.or
eilly.com/catalog/perlhks/
> Perl and CGI  - http://u
sers.easystreet.com/ovid/cgi_course/
> Personal blog - http://publiu
s-ovidius.livejournal.com/
> Tech blog     - http://use.perl.or
g/~Ovid/journal/
>



-- 
jeffa

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )