in reply to Re^3: [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 Tom... with you on the SO tone ... here's what I think is going on:
So, I propose you implement a Str method to bypass (Any) elements and format the object output for .put (or say ~$hamper).Use of uninitialized value element[2] of type Any in string context. Methods .^name, .raku, .gist, or .say can be used to stringify it to s +omething meaningful. in block <unit> at test.raku line 14
class Hamper { has $.name = 'Christmas Basket'; has @.items[3]; method TWEAK { @!items = ['Mince Pie', 'White Wine', 'Stinky Cheese'] unless +@!items.any.so; } method Str { "Name: {$!name}\nItems: [{@!items.grep(*.so).join(', ')}]\n"; } } given Hamper.new { .items[2] = 'Hard Cheese'; .put; } #Name: Christmas Basket #Items: [Mince Pie, White Wine, Hard Cheese] given Hamper.new( items => ['Fish', 'Canoe'] ) { .put; .items[2] = 'Bicycle'; .put; #.items[3] = 'Horse'; #fails.. Index 3 for dimension 1 out of +range (must be 0..2) #.items.push: 'Blue Nun'; #fails.. Cannot push a fixed-dimension a +rray } #Name: Christmas Basket #Items: [Fish, Canoe] #Name: Christmas Basket #Items: [Fish, Canoe, Bicycle]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: [Raku] Assigning defaults to attributes that are fixed length lists (and other confusions)
by jcb (Parson) on May 05, 2021 at 21:33 UTC |