On Sat, 12 Jan 2002, Dan Sugalski wrote:

> At 10:23 AM 1/12/2002 -0600, David M. Lloyd wrote:
> >On Sat, 12 Jan 2002, Dan Sugalski wrote:
> >
> > > At 09:05 PM 1/11/2002 -0600, David M. Lloyd wrote:
> > > >I have a design question here.  Why did we take the approach of having a
> > > >match method on every single vtable, instead of having a vtable for
> > > >regular expressions, and have regex be an object (like Perl 5)?
> > >
> > > So we could do:
> > >
> > >    @results = @foo ^=~ /bar/;
> > >
> > > Basically to allow hypermatches.
> >
> >Would that become something like this:
> >
> >@results = @foo.match(qr/bar/);
> >
> >where the 'match' method is called on the PerlArray object, or would it
> >be more like:
> >
> >@results = map { $_.match(qr/bar/); } @foo;  # Forgive the mixed p5/p6
> >
> >where the match method is called on each element of @foo?
>
> The former. The PerlArray object's perfectly justified in then calling
> match on each element inside itself.

Assuming that regular expressions can only ever match strings (via the =~
operator) and that the regex hyperoperator can only match *lists* of
strings, why do we need a special method on every single PMC to match
itself against a regex?  We *know* that we want the regex to match a
string of some kind, becuase that's what regexes do.  If we want to be
that flexible, we could just make a 'stringify-for-the-purposes-of-regex-
matching' method (althogh maybe with a slightly shorter name).  Because
when it comes down to it, that's what is going to happen anyway.  And if
that method is not implemented, it could default to the standard stringify
method.

As for worrying about the effects of hyper-operators, might it not make
more sense to have some kind of 'iterate' opcode?  It doesn't really make
sense for every PMC to have knowledge of how to match itself against a
regular expression in a 'hyper' sense; an iterator of some kind in
combination with the above mentioned stringify routine would get the job
done.

Here's an example that I hope communicates better than I do:

  @c = @a ^* @b;

This bit of example code isn't (I hope) going to do this:

  @c = @a.mul(@b);

because that's what I'd expect this to do:

  @c = @a * @b;

Instead, I'd think that @c = @a ^* @b would call some kind of iterator on
@a that knows how to traverse its own elements and call the appropriate
vtable function on each member.

We need iterators anyway, and (to me) this is more in line with Apoc. 3
because in all the examples, hyper-operators seem to act on lists, not
arrays:

($a, $b, $c, $d) = ($xx, $xy, $xz, $xq) ^+ ($yx, $yy, $yz, $yq);

That is, the array has no special knowledge of hyper-operators aside from
the fact that it knows that the operator requires one of each of its
contents.

Does this make sense?

- D

<[EMAIL PROTECTED]>

Reply via email to