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 "Fruitst

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

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?

I need help setting up a method

2020-12-19 Thread ToddAndMargo via perl6-users
Hi All, I have so far: class BadMath { has Int $.A; has Int $.B; method BadAdd() { my $Clinker = (-5..5).rand.truncate; return $!A + $!B + $Clinker; } } my $TwoPlusTwo = BadMath.new( A => 2, B=> 2 ); print $TwoPlusTwo.BadAdd ~ "\n"

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 ac

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 ~" app

Re: Missing NullPointerException

2020-12-19 Thread yary
Going back to Dec 3rd explanation: "... I had a chain of methods which should do some side effect. It all went fine only the side effect was not there. I then figured out after some time that one of methods returned Nil and somehow silently it did not do what I expected." This looks like an incom

Checking for nil return

2020-12-19 Thread yary
Is this a known issue, or my misunderstanding? > subset non-Nil where * !=== Nil; (non-Nil) > sub out-check($out) returns non-Nil { return $out } &out-check > out-check(44) 44 > out-check(Nil) Nil ^ Huh, I expected an exception on "out-check(Nil)" saying the return value failed the "returns" cons

Re: I need help setting up a method

2020-12-19 Thread Bruce Gray
> On Dec 19, 2020, at 6:40 PM, ToddAndMargo via perl6-users > wrote: > > Hi All, > > I have so far: > > > class BadMath { > has Int $.A; > has Int $.B; > > method BadAdd() { > my $Clinker = (-5..5).rand.truncate; > return $!A + $!B + $Clinker; >

Re: I need help setting up a method

2020-12-19 Thread ToddAndMargo via perl6-users
On 12/19/20 8:21 PM, Bruce Gray wrote: On Dec 19, 2020, at 6:40 PM, ToddAndMargo via perl6-users wrote: Hi All, I have so far: class BadMath { has Int $.A; has Int $.B; method BadAdd() { my $Clinker = (-5..5).rand.truncate; return $!A + $!B +

I need help understanding ".contains" method construction

2020-12-19 Thread ToddAndMargo via perl6-users
Hi All, https://github.com/rakudo/rakudo/blob/master/src/core.c/Str.pm6 337:multi method contains(Str:D: Str:D $needle --> Bool:D) { 338:nqp::hllbool(nqp::isne_i(nqp::index($!value,$needle,0),-1)) 339:} I "presume" in "abcd".contains("bc") "abcd" is `$!value`, and "bc" is $needle. Do

Re: I need help setting up a method

2020-12-19 Thread ToddAndMargo via perl6-users
On 12/19/20 8:21 PM, Bruce Gray wrote: With a custom `new` method, that could be shortened further to: say BadMath.new(2, 2).BadAdd; print BadMath.new(2, 2).BadAdd ~ "\n"; Default constructor for 'BadMath' only takes named arguments in block at line 1 What am I missing?