Hi Dean - thanks for that, you really cleared a lot up there.

"The code has @.items[3] is rw; creates a positional attribute which contains a fixed-length array with 3 elements. Thus, the array is truthy and the unless is not triggered."

I guess this is just a matter of convention and I am happy for fixed (non-zero) length arrays to be regarded as "true". That would make me right about the error message being slightly misleading, I think?

Thanks for steering me in the direction of writing my own accessor. I am aware that this is an option - though I haven't experimented with it yet. Actually I was hoping it could be done with has, as I am expecting (too much of?) Raku code to be pretty and boilerplate free. The solution you suggested is a great help - but does seem like quite a lot of code lines. I guess this is just because it's a workaround until the ability to assigning defaults to fixed length arrays gets implemented. Then it will be reduced back to a single line (I suppose).

Thanks again for your help :)


In reply to Re^2: [Raku] Assigning defaults to attributes that are fixed length lists (and other confusions) by tomgracey
in thread [Raku] Assigning defaults to attributes that are fixed length lists (and other confusions) by tomgracey

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.