Hi Richard, it doesn't appear to be a REPL-only result: user@mbook:~$ cat richard_closure.p6 class A { has &.f = -> { 'xyz' }}; my A $a .=new; say $a.f(); say $a.f.();
user@mbook:~$ raku richard_closure.p6 -> { #`(Block|140238954644472) ... } xyz user@mbook:~$ raku --version Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2020.10. Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d. Built on MoarVM version 2020.10. I took a brief glance at the StackOverflow post referred to elsewhere in this thread, but it's unclear to me how the two issues are related. I understood the results in the SO post to be a consequence of declaring private methods. Further study on my part is needed. HTH, Bill. On Sun, Jan 3, 2021 at 10:30 AM 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?