develooper Front page | perl.perl6.users | Postings from November 2019

Question about "colon syntax" for calling other methods on 'self'inside a method

Thread Next
From:
Raymond Dresens
Date:
November 16, 2019 13:29
Subject:
Question about "colon syntax" for calling other methods on 'self'inside a method
Message ID:
CALBLdeZLyeBibwgSK=fux4_qu9RVP2JvGtHeVKZbE8cYDBoMSQ@mail.gmail.com
Hello,

I have a question related to the 'colon syntax' of Raku, which allows
you to call methods without parenthesis like this:

    class Foo
    {
        method print($x, $y)
        {
            say "bar: {$x}, {$y}"
        }
    }

    my $a = Foo.new;

    $a.print: 3, 5; # ...this is what i mean with "colon syntax" ;)

It is possible to use this syntax to call methods on 'self' as well:

    class Bar is Foo
    {
        method printDefault
        {
            self.print: 8, 12
        }
    }

    my $b = Bar.new;

    $b.printDefault;

I use $. rather than 'self' in order to work with attributes inside
methods in my classes, well, ... mostly, because it does not seem
possible to do this (in rakudo, at least version 2019.07.1):

    class Baz is Foo
    {
        method printDefault
        {
            $.print: 8, 12
        }
    }

This yields a "Confused" error, stating that it expects a so-called
'colon pair'.

Is this intentional? Because I'm kind of confused as well about this,

I can live with this 'syntactical quirk', but I just keep wondering
about it because I'd personally expect that this "$.methodname: $args"
variant should "just work" as well...

...so "what gives"? ;)

Thanks for your insights!

Regards,

Raymond.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About