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 <perl6-users@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-users@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 >> >