I don't see how ::= (compile-time-bind) can be used as the initialize-if-non-existent operator.

I mean, it happens in the wrong phase (compile-time, not run-time) and it does the wrong thing (binding, not assignment).

For example:

        sub foo {
            state $count ::= 0;    # $count bound to constant zero
            $count++;              # Error, can't modify constant
            ...
        }


Or:


        sub bar ($start, ?$end ::= $start+1) {...}   # $end bound to 1.
                                                     # ($start is undef
                                                     #  at compile-time)

I think that all we need to do is to mentally distinguish "assignment" from "initialization":

        my $x = 1;    # initialization
           $x = 1;    # assignment

and say that initialization happens only on declarations and only once, at the very beginning of the lifetime of a variable. Thus:

        state $count = 0;    # initialization: happens only once
              $count = 1;    # assignment: happens every time

We then simply define the "=" in:

sub foo ( ?$bar = $baz ) {...}

to be an initialization (since it's on the declaration of the parameter).
If the parameter has already be bound to some other container, then that other container isn't at the start of its lifetime, so the initialization doesn't occur. If it hasn't been bound during the call, then it's just starting its existence and the initialization does occur.


And I don't think that allowing 20 different types of assignment in the parameter list of a subroutine actually helps at all. Especially since the vast majority of parameters in Perl 6 will be constant.

Damian



Reply via email to