One thing's for sure -- you're confused! I apologize if the following still doesn't help and/or is aggravating.

I really do not understand the use of the term "immutable".

To me it means "never changes".

There are three exceptions:

Construction

A data item must go from uninitialized/undefined to initialized/defined:

my $foo := 42; # declares $foo at compile time, binds it to immutable +42 at run-time BEGIN say $foo; # (Any) $foo = 99; # Cannot assign to an immutable value

Destruction

Memory is of course reclaimed at the end of a process at the latest if not garbage collected earlier (when no more references to it exist).

Referencing mutable data

One can have a reference that is itself immutable but which refers to mutable data. (Rats aren't mutable. So please don't think "ah, maybe this is the issue". I'm just trying to be complete in elaborating on the precise meaning of "immutable" in P6.) Thus:

my @foo := (42, $); @foo[1] = 99; say @foo; # (42 99) @foo[0] = 99; # Cannot modify an immutable Int

If your light bulb still hasn't lit up at least a little, perhaps it really is best for you to just wait until materials about P6 sufficiently improve (maybe years? maybe never?) and you have time to enjoy exploring them. (I don't think anyone can absorb new information well unless they're enjoying the process and it feels like you're very much not enjoying this at any level. I apologize if I've got that wrong.)

Alternatively, perhaps you could pick a line from my earlier comment in which I broke things down into tiny pieces, one that isn't clear to you, and we can then try to clear that up, and then another line, and so on?


In reply to Re^10: Small Perl 6 discoveries II, Rats by raiph
in thread [Perl6] Small discoveries I, __DATA__ by holli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.