Patrick R. Michaud <[EMAIL PROTECTED]> wrote:
Does anyone have any suggestions about what sort of PIR
code and/or PMCs we need to be able to do make the following
Perl 6 code work...?

Sure. I think Tcl handles this pretty nicely at the moment (although
Leo disagrees - he likes the Ref PMC route). The main idea is that
aliasing/binding enters the same PMC under a different name and that
assignment morphs the PMC.

    my @a;
    @a[4] = 'Hello';

    my $b := @a[4];
    say $b;                # says "Hello"

    @a[4] = [1, 2];
    say $b;                # says "1 2"


Here are the pieces I can fill in:

    #### my @a;
    new $P0, .Perl6List
    .lex '@a', $P0

    #### @a[4] = 'Hello';
    find_lex $P1, '@a'
    # (in general case we autovivify @a here if needed)
    set $P1[4], 'Hello'

    #### my $b := @a[4];
    find_lex $P2, '@a'
    $P2 = $P2[4]
    .lex '$b', $P2
    #### say $b;                # says "Hello"
    say $b

    #### @a[4] = [1, 2]
    $P2 = 'list'(1, 2)     # create a list
    find_lex $P3, '@a'
    # (in general case we autovivify @a here if needed)
    set $P3[4], $P2

With this scheme, you'd have to use assign in this last case instead
of set (with a morph to really make it safe) because you need to reuse
the same PMC:

    #### @a[4] = [1, 2]
    $P2 = 'list'(1, 2)
    find_lex $P3, '@a'
    $P3 = $P3[4]
    morph $P3, .Undef
    assign $P3, $P2

If you're only assigning your own PMCs, you can drop the morph (which
isn't technically safe anyway).

--
Matt Diephouse
http://matt.diephouse.com

Reply via email to