Larry Wall wrote:
Okay, I think this is worth bringing up to the top level.

Fact: Captures seem to be turning into a first-class data structure
that can represent:

    argument lists
    match results
    XML nodes
    anything that requires all of $, @, and % bits.

This is quite true, and worth thinking about. Captures are useful beasts.

Fact: We're currently going through contortions to try to get these to behave
when they're stored in a scalar variable: [,] =$capture

Fact: This contrasts with the ease with which we can request arrayness
and hashness using the @ and % sigils.

Consider this the first test of the first-classness of objects in Perl 6. You have an object that's something not entirely unlike:

  class Capture { has $.scalar; has @.array; hash %.hash  }

I think the addition of a sigil is the wrong way to go for several reasons, but most important among them is that there are going to be a lot of scalars that contain objects that are awfully capture-like, and they'll need whatever semantics we deem appropriate for captures too.

For this reason, I'd suggest putting away the Latin-1 glyphset and instead focusing on developing operators to act on containers with multiple access methods and their expanded forms.

First of all, I need a word. I'm going to call an expanded capture a "signature" even though that's a bit too metaish. I don't encourage others to use this term, but it helps me to get my head around this. A signature is a bit like a list. It has no data type that you can point to directly. Signatures are also probably lazy like lists.

When we want to turn a capture that is stored in a scalar into a signature, we need an operator that performs that action, and unambiguously does NOT perform the action of turning it into a list. I suggested some in my previous message (such as <-- and $\).

Subroutines just so happen to take signatures, so you can invoke them with one:

        foo(<-- $capture);
        foo($\  $capture);

Now, you need to be able to go in the other direction. You need to be able to assemble a signature and convert it into a capture. This, we already have:

        $cap = \(<-- $othercap, $a, :$b)
        $cap = \($\  $othercap, $a, :$b)

This would transform $othercap from a capture to a signature, add in a positional and a named value and then re-integrate the resulting signature as a new capture.

Calling subroutines with such a thing looks nice and clean:

        $values = \([EMAIL PROTECTED], [EMAIL PROTECTED], $c, :mean<1>);
        $avg1 = avg(<-- $values, :undef<ignore>);
        $avg2 = avg(<-- $values, :undef<iszero>);

That's as simple as you can get, and we didn't have to promote captures to a new kind of sigil type to do it.

Reply via email to