in reply to Re: [Raku] Assigning defaults to attributes that are fixed length lists (and other confusions)
in thread [Raku] Assigning defaults to attributes that are fixed length lists (and other confusions)
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 :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: [Raku] Assigning defaults to attributes that are fixed length lists (and other confusions)
by tomgracey (Scribe) on Apr 29, 2021 at 15:53 UTC | |
by p6steve (Sexton) on May 03, 2021 at 22:30 UTC | |
by jcb (Parson) on May 05, 2021 at 21:33 UTC |