develooper Front page | perl.perl6.users | Postings from January 2021

Extra . needed

Thread Next
From:
Richard Hainsworth
Date:
January 3, 2021 18:30
Subject:
Extra . needed
Message ID:
5ab27fcb-4f1d-987c-0147-3f4adaaddd7d@gmail.com
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?

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