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


In reply to [raku] what accessors are actually autogenerated for @.array attributes? 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.