Luke Palmer <[EMAIL PROTECTED]> writes:

> On 7/26/05, "TSa (Thomas Sandlaß)" <[EMAIL PROTECTED]> wrote:
>> Piers Cawley wrote:
>> > I would like to be able to iterate over all the
>> > objects in the live set.
>> 
>> My Idea actually is to embedd that into the namespace syntax.
>> The idea is that of looking up non-negativ integer literals
>> with 0 beeing the namespace owner.
>> 
>>    for ::Namespace -> $instance
>>    {
>>       if +$instance != 0 { reconfigure $instance }
>>    }
>
> Oh, so a namespace can behave as an array then.  Well, to avoid
> auto-flattening problems in other, more common places, we ought to
> make that:
>
>     for *::Namespace -> $instance {...}
>
> However, this is very huffmanly incorrect.  First of all, what you're
> doing may take a quarter of a second or more for a large program
> (which isn't a short amount of time by any means).  Second, the fact
> that you're using it means you're doing something evil.  Third, only a
> fraction of 1/omega perl programmers will be using this feature. 
> Therefore, it should probably look like:
>
>     use introspection;
>     for introspection::ALL_INSTANCES(::Namespace) -> $instance {...}

And if my proposal or something like it were accepted, the implementation could
simply look like:

  module introspection {
    class Class is extended {
      method all_instances($class:) {
        fail unless $*PLATFORM.GC.can_iterate_over_liveset;
        $*PLATFORM.GC.grep -> $instance { $instance.isa($class) }
      }
    }

    sub ALL_INSTANCES($class) {
      $class.all_instances
    }
  }
     
The point about my proposal to have the garbage collector or something like it
expose methods to iterate over the live set isn't that it's syntactically
gorgeous, but that it's a useful minimal behaviour that can be used to
implement nicer syntaxes which can be loaded as required. If we're going to
allow such reflective stuff (on platforms that can do it) then there needs to
be some minimal core functionality that other modules can use. The point about
iterating over the live set is that it's essentially free until you use it; the
garbage collector must *already* hold onto the information needed to do the
iteration.

Reply via email to