Yeah, right. $FruitStand.apples is not a direct access to the attribute,
but a method invocation (a call to a method implicitly created by Raku), so
it doesn't get interpolated within the string. So it should be outside the
string or used with a code interpolation block.
For example:
say "Fruitstand in {$FruitStand.location} has {$FruitStand.apples} apples.";
or
say "Fruitstand in ", $FruitStand.location, "has ", $FruitStand.apples, "
apples.";
or the construct with the ~ concatenation operator that you used.
Cheers,
Laurent..
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Garanti
sans virus. www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
Le ven. 18 déc. 2020 à 23:55, ToddAndMargo via perl6-users <
[email protected]> a écrit :
> On 12/18/20 9:42 AM, William Michels via perl6-users wrote:
> > Hi Laurent, I get:
> >
> > Fruitstand in Fruit<140431957910656>.location has
> > Fruit<140431957910656>.apples apples.
> >
> > [Rakudo v2020.10]
> >
> > Best, Bill.
> >
>
> Hi Bill,
>
> From my notes in progress:
>
> -T
>
>
> *** addressing values inside and object ***
>
> Reading:
> say $FruitStand.apples
> 400
>
> $FruitStand.apples.say
> 400
>
> print $FruitStand.location ~ " has " ~ $FruitStand.apples ~"
> apples in stock\n";
> Cucamonga has 400 apples in stock
>
> Note: an "oops!". Separate the variables from the string, or else:
> say "$FruitStand.location has $FruitStand.apples apples in
> stock";
> Fruit<79300336>.location has Fruit<79300336>.apples apples in
> stock
>
> Writing (must be declared as "rw"):
>