tomgracey has asked for the wisdom of the Perl Monks concerning the following question:
Hello PerlRaku Monks
I have another (absurdly basic) Raku question. Consider the following:
class Fish { has @.scales is rw; } my $fish = Fish.new; $fish.scales('green','blue','yellow');
This doesn't work. I get:
Too many positionals passed; expected 1 argument but got 4
The "1 argument" it appears to be expecting seems to be self. ie it seems specifying @.scales creates only the get accessor. Is this correct? Do we have to create our own set accessors for array-type attributes?
I may be looking in the wrong place, but I could not find any documentation on exactly what accessors are autogenerated - the docs seem to just say "specify the period twigil to have accessors autogenerated".
Part of my problem may be that I am not familiar enough with the various inspection methods. Possibly there is a way to see exactly what methods are being created. For example the ^methods meta-method does return a list of methods, but without any accompanying information - e.g is it a multimethod etc. So scales would come up in the list if $fish.^methods is called, but it would seem only once regardless if there is a setter. Is anyone aware of a way of getting a more detailed list?
Sorry again for the basic question, but sometimes it seems better to get some direct feedback rather than trawling endlessly in the hope of finding examples. (I looked through vast swathes of code for an example of setting an array after the object has been created and didn't happen on any at all. Plenty of setting it via new of course. Not sure if I was just unlucky.)
Anyway thanks in advance for your help
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [raku] what accessors are actually autogenerated for @.array attributes?
by choroba (Cardinal) on May 06, 2021 at 15:00 UTC | |
|
Re: [raku] what accessors are actually autogenerated for @.array attributes?
by markldevine (Initiate) on May 10, 2021 at 20:21 UTC | |
by jdporter (Paladin) on May 11, 2021 at 14:19 UTC | |
|
Re: [raku] what accessors are actually autogenerated for @.array attributes?
by p6steve (Sexton) on May 11, 2021 at 21:33 UTC | |
|
Re: [raku] what accessors are actually autogenerated for @.array attributes?
by b2gills (Novice) on May 13, 2021 at 16:01 UTC |