Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Elaborate on the "my Foo .= new()" idiom
  • Loading branch information
lizmat committed Jun 12, 2018
1 parent dbdd6ac commit b1bfd97
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions doc/Language/5to6-perlop.pod6
Expand Up @@ -204,12 +204,24 @@ $x = $ok ?? $yes !! $no; # Perl 6
Although not fully documented, S03 indicates that the mathematical and
logical assignment operators should work as you would expect. The one
noticeable change is that C<.=> calls a mutating method on the object on
the left, while C<~=> is the string concatenation assignment, as you
might expect with the changes in C<.> and C<~>. Also, the bitwise
assignment operators are likely not separated into numeric and string
versions (C<&=>, etc., vs. C<&.=>, etc.), as that feature is currently
experimental in Perl 5 itself - although, again, this is not
specifically documented.
the left (which can also be a type-object). This allows for the following
useful idiom:
=begin code
class LongClassName {
has $.frobnicate;
}
my LongClassName $bar .= new( frobnicate => 42 ); # no need to repeat class name
=end code
This ensures that C<$bar> will only be able to contain a C<LongClassName>
object, as well not having to repeat (and possibly misspell) the class name.
C<~=> is the string concatenation assignment, as you might expect with the
changes in C<.> and C<~>. Also, the bitwise assignment operators are likely
not separated into numeric and string versions (C<&=>, etc., vs. C<&.=>, etc.),
as that feature is currently experimental in Perl 5 itself - although, again,
this is not specifically documented.
=head2 Comma Operator
Expand Down

2 comments on commit b1bfd97

@b2gills
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last statement also needs changing as Perl 6 uses +&= and ~&= for the numeric and string bitwise assignment operators.

@lizmat
Copy link
Collaborator Author

@lizmat lizmat commented on b1bfd97 Jun 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patches accepted :-) That last bit was just reformatted.

Please sign in to comment.