Aaron pointed out:

   > But, in terms of constants, it seems to me that there's no
   > difference. They both have only one value that is assigned
   > when the module/class is parsed.

Well, in *practice* there's no difference, but in their mystical essences,
they're completely different. ;-)


   > > I'd do that like so (using Larry's preferred syntax):
   > [...]
   > >         method INIT ($idval) { $.id := $idval }
   >
   > Hm... that looks to me like a regular ":="; is it?

Yep.


   > If so, what good is "is const" if you can override it with
   > a ":="? Am I missing something?

That's a binding, not an assignment.

C<is const> means: "Once declared cannot be *assigned* to".

But that doesn't mean one can't *bind* a new value to the variable
(which would retain its C<const>-induced unassignability after the binding).

Consider the following Perl 5:

        # CREATE CONSTANT
        *constant = \7;
        print "$constant\n";

        # TRY TO ASSIGN (THROWS EXCEPTION)
        eval { $constant = -7 } or print $@;
        print "$constant\n";

        # TRY TO REBIND (WORKS FINE)
        eval { *constant = \-7) } or print $@;
        print "$constant\n";


The analogy in Perl 6 would be:

        # CREATE CONSTANT
        my $constant is const = 7;
        print "$constant\n";

        # TRY TO ASSIGN (THROWS EXCEPTION)
        try { $constant = -7 } catch { print $! }
        print "$constant\n";

        # TRY TO REBIND (WORKS FINE)
        try { $constant := -7) } catch { print $! }
        print "$constant\n";


Damian

Reply via email to