Hi Timo,

Thanks for the answer:

> the liskov substitution principle
I didn't knew about this principle. I'm now going down the rabbit hole.
Is this always the case for all the derived classes in Raku?

Best regards,
David Santiago

Timo Paulssen <t...@wakelift.de> escreveu no dia terça, 11/02/2020 à(s) 13:32:
>
> On 11/02/2020 14:14, David Santiago wrote:
> > Awesome explanation! Thank you!
> >
> > BTW,
> >> my Blob $read = Buf.new;
> > Is it creating either a Blob or a Buf?
> >
> > Regards,
> > David Santiago
>
>
> Hi David,
>
> "my Blob $read" will define the variable $read to 1) only accept things
> that typecheck against Blob, and 2) has the starting value of Blob (the
> Blob type object). Assigning Buf.new to it will assign the newly created
> Buf object to the variable, because a Buf Is-A Blob (by the liskov
> substitution principle, everywhere you can use a Blob, you can also use
> a Buf, but not the other way around).
>
> BTW, assigning to a variable with a % or @ sigil behaves differently.
> That is called "list assignment" and will actually use whatever type the
> % or @ variable is defined to use (Hash and Array by default) and store
> the values from the right-hand side of the assignment into the existing
> object. This is why "my %foo = SetHash.new(<a b c>)" will result in a
> Hash. For this example, you would want "my %foo is SetHash = <a b c>"
> instead.
>
> Hope that clears things up
>   - Timo
>

Reply via email to