Re: How do I address individual elements inside an object

2020-12-19 Thread ToddAndMargo via perl6-users

On 12/19/20 4:49 PM, Brad Gilbert wrote:

You can interpolate a method call in a string, but you need the parens.

     say "$FruitStand.location() has $FruitStand.apples() apples in stock";


Cool!  Now four ways of doing it:

  print $FruitStand.location ~ "has " ~ $FruitStand.apples ~" 
apples in stock\n";


  print "Fruitstand in {$FruitStand.location} has 
{$FruitStand.apples} apples\n";


  print "Fruitstand in ", $FruitStand.location,  "has ", 
$FruitStand.apples, " apples\n";


  print "$FruitStand.location() has $FruitStand.apples() apples in 
stock";


Re: How do I address individual elements inside an object

2020-12-19 Thread Brad Gilbert
You can interpolate a method call in a string, but you need the parens.

say "$FruitStand.location() has $FruitStand.apples() apples in stock";

On Sat, Dec 19, 2020 at 4:28 AM Laurent Rosenfeld via perl6-users <
perl6-us...@perl.org> wrote:

> 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..
>
>
> 
>  Garanti
> sans virus. www.avast.com
> 
> <#m_8010816652420510664_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> Le ven. 18 déc. 2020 à 23:55, ToddAndMargo via perl6-users <
> perl6-us...@perl.org> 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"):
>>
>


Re: How do I address individual elements inside an object

2020-12-19 Thread ToddAndMargo via perl6-users

apples.";


Is the "." at the end of the apples literal or syntax?


Re: How do I address individual elements inside an object

2020-12-19 Thread William Michels via perl6-users
Great, Laurent!
Works fine (and Todd's as well).
Thank you for the explanation.

--B.

On Sat, Dec 19, 2020 at 2:27 AM Laurent Rosenfeld via perl6-users <
perl6-us...@perl.org> wrote:

> 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..
>
>
> 
>  Garanti
> sans virus. www.avast.com
> 
> <#m_8427144409934787973_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> Le ven. 18 déc. 2020 à 23:55, ToddAndMargo via perl6-users <
> perl6-us...@perl.org> 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"):
>>
>


Re: How do I address individual elements inside an object

2020-12-19 Thread Laurent Rosenfeld via perl6-users
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..


Garanti
sans virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Le ven. 18 déc. 2020 à 23:55, ToddAndMargo via perl6-users <
perl6-us...@perl.org> 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"):
>


Re: How do I address individual elements inside an object

2020-12-18 Thread ToddAndMargo via perl6-users

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"):


Re: How do I address individual elements inside an object

2020-12-18 Thread William Michels via perl6-users
Hi Laurent, I get:

Fruitstand in Fruit<140431957910656>.location has
 Fruit<140431957910656>.apples apples.

[Rakudo v2020.10]

Best, Bill.


On Fri, Dec 18, 2020 at 5:29 AM Laurent Rosenfeld via perl6-users <
perl6-us...@perl.org> wrote:

> Hi Todd,
>
> 1. Yes, a class is a blueprint for manufacturing objects, you can
> construct as many object as you want.
>
> 2. As an example, you can try:
>
> say " Fruitstand in $FruitStand.location has  $FruitStand.apples apples.";
>
> 2. As you declared your class the object attributes will not be mutable.
> But if you had declared the apple attribute like so in the class:
>
> has UInt $.apples is rw;
>
> then you could write:
>
> $FruitStand.apples += 42;
>
> Cheers,
> Laurent.
>
> Le ven. 18 déc. 2020 à 08:12, ToddAndMargo via perl6-users <
> perl6-us...@perl.org> a écrit :
>
>> Hi All,
>>
>> class Fruit {
>> has Str $.location;
>> has UInt $.apples;
>> has UInt $.oranges;
>> has UInt $.bananas;
>> }
>>
>> my $FruitStand = Fruit.new( location => "Cucamonga",
>> apples   => 400,
>> oranges  => 200,
>> bananas  => 50  );
>>
>> 1)  am I correct that I can make as many objects as I
>>  want out of a particular class?
>>
>> 2 ) what is the syntax to read an element inside an
>>  object?
>>
>> 3)  what is the syntax to write to an element inside an
>>  object?
>>
>> I am confused, again.
>>
>> -T
>>
>


Re: How do I address individual elements inside an object

2020-12-18 Thread Parrot Raiser
Although it's a standard term, "class" has a misleading connotation of "set".
Using the "fruit" example, the class Fruit should indicate a set of
relevant properties for a fruit, such as name, colour, taste, size,
possibly cost/kilo. Individual variables can be defined as Fruit-type
objects. Then $apple might be declared  with Fruit.new as "apple",
"red", "sweet", 100g, 3.00. The class has methods to do things with
the values, such as return the colour. say $apple.colour would then
output "red", while $banana (another Fruit) in $banana.colour would
output "green". ($banana.ripen would be a method defined in the class
to change "green" to "yellow" and "yellow" to "brown".

On 12/18/20, Laurent Rosenfeld via perl6-users  wrote:
> Hi Todd,
>
> 1. Yes, a class is a blueprint for manufacturing objects, you can construct
> as many object as you want.
>
> 2. As an example, you can try:
>
> say " Fruitstand in $FruitStand.location has  $FruitStand.apples apples.";
>
> 2. As you declared your class the object attributes will not be mutable.
> But if you had declared the apple attribute like so in the class:
>
> has UInt $.apples is rw;
>
> then you could write:
>
> $FruitStand.apples += 42;
>
> Cheers,
> Laurent.
>
> Le ven. 18 déc. 2020 à 08:12, ToddAndMargo via perl6-users <
> perl6-us...@perl.org> a écrit :
>
>> Hi All,
>>
>> class Fruit {
>> has Str $.location;
>> has UInt $.apples;
>> has UInt $.oranges;
>> has UInt $.bananas;
>> }
>>
>> my $FruitStand = Fruit.new( location => "Cucamonga",
>> apples   => 400,
>> oranges  => 200,
>> bananas  => 50  );
>>
>> 1)  am I correct that I can make as many objects as I
>>  want out of a particular class?
>>
>> 2 ) what is the syntax to read an element inside an
>>  object?
>>
>> 3)  what is the syntax to write to an element inside an
>>  object?
>>
>> I am confused, again.
>>
>> -T
>>
>


Re: How do I address individual elements inside an object

2020-12-18 Thread Laurent Rosenfeld via perl6-users
Hi Todd,

1. Yes, a class is a blueprint for manufacturing objects, you can construct
as many object as you want.

2. As an example, you can try:

say " Fruitstand in $FruitStand.location has  $FruitStand.apples apples.";

2. As you declared your class the object attributes will not be mutable.
But if you had declared the apple attribute like so in the class:

has UInt $.apples is rw;

then you could write:

$FruitStand.apples += 42;

Cheers,
Laurent.

Le ven. 18 déc. 2020 à 08:12, ToddAndMargo via perl6-users <
perl6-us...@perl.org> a écrit :

> Hi All,
>
> class Fruit {
> has Str $.location;
> has UInt $.apples;
> has UInt $.oranges;
> has UInt $.bananas;
> }
>
> my $FruitStand = Fruit.new( location => "Cucamonga",
> apples   => 400,
> oranges  => 200,
> bananas  => 50  );
>
> 1)  am I correct that I can make as many objects as I
>  want out of a particular class?
>
> 2 ) what is the syntax to read an element inside an
>  object?
>
> 3)  what is the syntax to write to an element inside an
>  object?
>
> I am confused, again.
>
> -T
>


How do I address individual elements inside an object

2020-12-17 Thread ToddAndMargo via perl6-users

Hi All,

   class Fruit {
   has Str $.location;
   has UInt $.apples;
   has UInt $.oranges;
   has UInt $.bananas;
   }

   my $FruitStand = Fruit.new( location => "Cucamonga",
   apples   => 400,
   oranges  => 200,
   bananas  => 50  );

1)  am I correct that I can make as many objects as I
want out of a particular class?

2 ) what is the syntax to read an element inside an
object?

3)  what is the syntax to write to an element inside an
object?

I am confused, again.

-T