How to inject methods

Stephen Weeks tene at allalone.org
Mon Jun 28 23:09:08 UTC 2010


Not long ago, Andrew Whitworth proclaimed...
> Date: Mon, 28 Jun 2010 13:52:43 -0400
> Subject: How to inject methods
> I'm running into a problem in Kakapo caused by the TT #389 changes.
> Kakapo defines a number of extension methods for built-in PMC types
> and injects those methods into the respective classes/pmcproxies.
> However, this mechanism is significantly harder after the TT #389
> fixes and in some cases I haven't found any way to do the things that
> I need.
> 
> I would like to try and fix some of the things that I think are
> broken, and add some new functionality to replace the things that we
> lost in the TT #389 fix. I've been looking around and I can't really
> find good rationale for the change. The comments in the Trac ticket
> (and in the old RT ticket) don't really explain why the change was
> needed or what problems it intended to solve. If I try to add new
> functionality for what Kakapo needs, I want to make sure that I am not
> breaking something that people are relying on. Can somebody give me a
> rundown of what, exactly, TT #389 was supposed to accomplish?
> 
> Is the issue that it's absolutely terrible design to have the methods
> available from the namespace in any way, or that methods shouldn't get
> mixed in with other types of objects that the namespace stores?
> Having the methods stored in the namespace now but not being able to
> access them is pretty weak, especially when there are many reasons why
> we would want to be able to access them there.

I've read this thread, and I'm not quite sure I understand exactly what
you're trying to do here.  By my reading, you have a bunch of methods
listed in a pir file, and you want them to be entries in the namespace,
like they were before.  Can't you just mark them as :nsentry?  Isn't
that exactly what that flag is for, and added as part of the TT #389
work specifically to allow an option for getting the current semantics?

See the attached pir file demonstrating what I think you're asking for,
and that :nsentry provides it.

If I'm wrong and that doesn't help, can you provide a small pir example
of what you're trying to do here and why :nsentry doesn't help, so us
slower members of the audience can follow along? :)

(I'm having mail issues right now... there might be multiple copies of
this mail coming in... sorry.)
-------------- next part --------------
.sub main :main
    .local pmc ns, item, itr
    ns = get_namespace ['Lol']
    itr = iter ns
  loop:
    unless itr goto end_loop
    item = shift itr
    say item
    goto loop
  end_loop:
    say 'Done!'
.end

.namespace ['Lol']

.sub 'method-nsentry' :method :nsentry
    say 'lol'
.end

.sub 'method-no-nsentry' :method
    say 'lol'
.end

.sub 'not-method'
    say 'lol'
.end


More information about the parrot-dev mailing list