in reply to Re^7: Small Perl 6 discoveries II, Rats
in thread [Perl6] Small discoveries I, __DATA__
the following operation converts $x from a Rat to a FatRat
That's a a mutable "container" aka a variable (a Scalar in this case) containing one immutable value (a Rat) then another immutable value (a FatRat).
# Declare a new identifier $x and bind it to a new mutable Scalar cont +ainer: my $x; # Assign a value into the Scalar: $x # An LHS reference to a Scalar returns the Scalar. = # = is assignment. The LHS decides what to do with i +t. 9.9; # Creates a new immutable Rat. # VAR macro returns what the identifier is bound to: say $x.VAR.^name; # Scalar -- the type of variable bound to $x. # All other uses of $x or a Scalar on RHS return the value assigned in +to the Scalar: say $x; # 9.9 say $x.^name; # Rat -- the type of the value assigned into the Sca +lar. $x *= 2; # This is equivalent to ... $x = $x * 2; # ... which assigns result of RHS expression into Sc +alar on LHS. say $x; # 39.6
Hth.
|
|---|