You've already asked a similar question.

https://stackoverflow.com/questions/54033524/perl6-correctly-passing-a-routine-into-an-object-variable

When you call $a.f() you are getting the value in &!f which is a function.

When you call $a.f().() you are getting the value in &!f, and then also
calling that function.

You don't need the parens on a method call if they are empty.

So $a.f() is the same as $a.f
and $a.f().() is the same as $a.f.()

On Sun, Jan 3, 2021 at 12:30 PM Richard Hainsworth <rnhainswo...@gmail.com>
wrote:

> I was playing with classes and adding a closure to an attribute.
>
> I discovered that to call a closure on object I need `.()` rather than
> just `()`. See REPL below.
>
> raku
> Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2020.12.
> Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.
> Built on MoarVM version 2020.12.
>
> To exit type 'exit' or '^D'
> > class A { has &.f = -> { 'xyz' }}
> (A)
> > my A $a .=new
> A.new(f => ->  { #`(Block|94272504746848) ... })
> > say $a.f()
> ->  { #`(Block|94272504749656) ... }
> > say $a.f.()
> xyz
> >
>
>
> I was wondering whether it was intended for `()` to return something other
> than `.()`?
>
> My first thought would be that `.()` would have the same syntactic sugar
> as `.[]` on an Array object.
>
> I looked in the Documentation and in Classes found
>             &!callback();
> inside class Task.
>
> So I think there may be something a bit wrong. Or is this an artifact of
> REPL?
>

Reply via email to