Extra . needed

--------------AAFCA324C7D22E50C15DBC6A
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

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?

--------------AAFCA324C7D22E50C15DBC6A
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>

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

--------------AAFCA324C7D22E50C15DBC6A--
0
rnhainsworth
1/3/2021 6:30:00 PM
perl.perl6.users 1545 articles. 0 followers. Follow

3 Replies
248 Views

Similar Articles

[PageSpeed] 25

--00000000000018846905b803923a
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

You've already asked a similar question.

https://stackoverflow.com/questions/54033524/perl6-correctly-passing-a-rout=
ine-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 <rnhainsworth@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 =F0=9D=90=91=F0=9D=90=9A=F0=9D=90=A4=F0=9D=90=AE=F0=9D=90=9D=
=F0=9D=90=A8=E2=84=A2 v2020.12.
> Implementing the =F0=9D=90=91=F0=9D=90=9A=F0=9D=90=A4=F0=9D=90=AE=E2=84=
=A2 programming language v6.d.
> Built on MoarVM version 2020.12.
>
> To exit type 'exit' or '^D'
> > class A { has &.f =3D -> { 'xyz' }}
> (A)
> > my A $a .=3Dnew
> A.new(f =3D> ->  { #`(Block|94272504746848) ... })
> > say $a.f()
> ->  { #`(Block|94272504749656) ... }
> > say $a.f.()
> xyz
> >
>
>
> I was wondering whether it was intended for `()` to return something othe=
r
> 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?
>

--00000000000018846905b803923a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">You&#39;ve already asked a similar question.<div><br></div=
><div><a href=3D"https://stackoverflow.com/questions/54033524/perl6-correct=
ly-passing-a-routine-into-an-object-variable">https://stackoverflow.com/que=
stions/54033524/perl6-correctly-passing-a-routine-into-an-object-variable</=
a><br></div><div><br></div><div>When you call $a.f() you are getting the va=
lue in &amp;!f which is a function.</div><div><br></div><div>When you call =
$a.f().() you are getting the value in &amp;!f, and then also calling that =
function.</div><div><br></div><div>You don&#39;t need the parens on a metho=
d call if they are empty.</div><div><br></div><div>So $a.f() is the same as=
 $a.f</div><div>and $a.f().() is the same as $a.f.()</div></div><br><div cl=
ass=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Jan 3, 20=
21 at 12:30 PM Richard Hainsworth &lt;<a href=3D"mailto:rnhainsworth@gmail.=
com">rnhainsworth@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,=
204,204);padding-left:1ex">
 =20

   =20
 =20
  <div>
    <p>I was playing with classes and adding a closure to an attribute.</p>
    <p>I discovered that to call a closure on object I need `.()` rather
      than just `()`. See REPL below.</p>
    <p>raku<br>
      Welcome to =F0=9D=90=91=F0=9D=90=9A=F0=9D=90=A4=F0=9D=90=AE=F0=9D=90=
=9D=F0=9D=90=A8=E2=84=A2 v2020.12.<br>
      Implementing the =F0=9D=90=91=F0=9D=90=9A=F0=9D=90=A4=F0=9D=90=AE=E2=
=84=A2 programming language v6.d.<br>
      Built on MoarVM version 2020.12.<br>
      <br>
      To exit type &#39;exit&#39; or &#39;^D&#39;<br>
      &gt; class A { has &amp;.f =3D -&gt; { &#39;xyz&#39; }}<br>
      (A)<br>
      &gt; my A $a .=3Dnew<br>
      A.new(f =3D&gt; -&gt;=C2=A0 { #`(Block|94272504746848) ... })<br>
      &gt; say $a.f()<br>
      -&gt;=C2=A0 { #`(Block|94272504749656) ... }<br>
      &gt; say $a.f.()<br>
      xyz<br>
      &gt; <br>
    </p>
    <p><br>
    </p>
    <p>I was wondering whether it was intended for `()` to return
      something other than `.()`?</p>
    <p>My first thought would be that `.()` would have the same
      syntactic sugar as `.[]` on an Array object.</p>
    <p>I looked in the Documentation and in Classes found <br>
    </p>
    <div><span><span><span><span><span></span></span></span></span></span><=
/div>
    <div><span><span><span><span><span>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0</span><span><span><span>&amp;</span></=
span><span><span>!</span></span><span><span>callback</span></span></span><s=
pan>();</span></span></span></span></span></div>
    <div><span><span><span><span><span>inside class Task.</span></span></sp=
an></span></span></div>
    <div><span><span><span><span><span><br>
              </span></span></span></span></span></div>
    <div><span><span><span><span><span>So I think there may be something a =
bit wrong.
                Or is this an artifact of REPL?<br>
              </span></span></span></span></span></div>
  </div>

</blockquote></div>

--00000000000018846905b803923a--
0
b2gills
1/3/2021 6:59:08 PM
Hi Richard, it doesn't appear to be a REPL-only result:

user@mbook:~$ cat richard_closure.p6
class A { has &.f =3D -> { 'xyz' }};
my A $a .=3Dnew;
say $a.f();
say $a.f.();

user@mbook:~$ raku richard_closure.p6
->  { #`(Block|140238954644472) ... }
xyz
user@mbook:~$ raku --version
Welcome to =F0=9D=90=91=F0=9D=90=9A=F0=9D=90=A4=F0=9D=90=AE=F0=9D=90=9D=F0=
=9D=90=A8=E2=84=A2 v2020.10.
Implementing the =F0=9D=90=91=F0=9D=90=9A=F0=9D=90=A4=F0=9D=90=AE=E2=84=A2 =
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
<rnhainsworth@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 ju=
st `()`. See REPL below.
>
> raku
> Welcome to =F0=9D=90=91=F0=9D=90=9A=F0=9D=90=A4=F0=9D=90=AE=F0=9D=90=9D=
=F0=9D=90=A8=E2=84=A2 v2020.12.
> Implementing the =F0=9D=90=91=F0=9D=90=9A=F0=9D=90=A4=F0=9D=90=AE=E2=84=
=A2 programming language v6.d.
> Built on MoarVM version 2020.12.
>
> To exit type 'exit' or '^D'
> > class A { has &.f =3D -> { 'xyz' }}
> (A)
> > my A $a .=3Dnew
> A.new(f =3D> ->  { #`(Block|94272504746848) ... })
> > say $a.f()
> ->  { #`(Block|94272504749656) ... }
> > say $a.f.()
> xyz
> >
>
>
> I was wondering whether it was intended for `()` to return something othe=
r 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?
0
perl6
1/3/2021 9:51:14 PM
--------------CAF64EFD70C99B1E85B2A5A2
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Mea culpa. Super embarrassing.

Comes from having to do something else for a year.

Thanks Brad


On 03/01/2021 18:59, Brad Gilbert wrote:
> You've already asked a similar question.
>
> https://stackoverflow.com/questions/54033524/perl6-correctly-passing-a-routine-into-an-object-variable 
> <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 
> <rnhainsworth@gmail.com <mailto:rnhainsworth@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?
>

--------------CAF64EFD70C99B1E85B2A5A2
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Mea culpa. Super embarrassing.<br>
    </p>
    <p>Comes from having to do something else for a year.</p>
    <p>Thanks Brad</p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 03/01/2021 18:59, Brad Gilbert
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAD2L-T0yEEvLoAMFiwQAA6VkzWfr2hS0J7xtW0bswVt_F2zX6w@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">You've already asked a similar question.
        <div><br>
        </div>
        <div><a
href="https://stackoverflow.com/questions/54033524/perl6-correctly-passing-a-routine-into-an-object-variable"
            moz-do-not-send="true">https://stackoverflow.com/questions/54033524/perl6-correctly-passing-a-routine-into-an-object-variable</a><br>
        </div>
        <div><br>
        </div>
        <div>When you call $a.f() you are getting the value in &amp;!f
          which is a function.</div>
        <div><br>
        </div>
        <div>When you call $a.f().() you are getting the value in
          &amp;!f, and then also calling that function.</div>
        <div><br>
        </div>
        <div>You don't need the parens on a method call if they are
          empty.</div>
        <div><br>
        </div>
        <div>So $a.f() is the same as $a.f</div>
        <div>and $a.f().() is the same as $a.f.()</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Sun, Jan 3, 2021 at 12:30
          PM Richard Hainsworth &lt;<a
            href="mailto:rnhainsworth@gmail.com" moz-do-not-send="true">rnhainsworth@gmail.com</a>&gt;
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div>
            <p>I was playing with classes and adding a closure to an
              attribute.</p>
            <p>I discovered that to call a closure on object I need
              `.()` rather than just `()`. See REPL below.</p>
            <p>raku<br>
              Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2020.12.<br>
              Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.<br>
              Built on MoarVM version 2020.12.<br>
              <br>
              To exit type 'exit' or '^D'<br>
              &gt; class A { has &amp;.f = -&gt; { 'xyz' }}<br>
              (A)<br>
              &gt; my A $a .=new<br>
              A.new(f =&gt; -&gt;  { #`(Block|94272504746848) ... })<br>
              &gt; say $a.f()<br>
              -&gt;  { #`(Block|94272504749656) ... }<br>
              &gt; say $a.f.()<br>
              xyz<br>
              &gt; <br>
            </p>
            <p><br>
            </p>
            <p>I was wondering whether it was intended for `()` to
              return something other than `.()`?</p>
            <p>My first thought would be that `.()` would have the same
              syntactic sugar as `.[]` on an Array object.</p>
            <p>I looked in the Documentation and in Classes found <br>
            </p>
            <div><span><span><span><span><span></span></span></span></span></span></div>
            <div><span><span><span><span><span>            </span><span><span><span>&amp;</span></span><span><span>!</span></span><span><span>callback</span></span></span><span>();</span></span></span></span></span></div>
            <div><span><span><span><span><span>inside class Task.</span></span></span></span></span></div>
            <div><span><span><span><span><span><br>
                      </span></span></span></span></span></div>
            <div><span><span><span><span><span>So I think there may be
                        something a bit wrong. Or is this an artifact of
                        REPL?<br>
                      </span></span></span></span></span></div>
          </div>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>

--------------CAF64EFD70C99B1E85B2A5A2--
0
rnhainsworth
1/4/2021 6:51:46 PM
Reply: