Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc >>. on lists of Callables #1643

Closed
gfldex opened this issue Oct 31, 2017 · 7 comments
Closed

doc >>. on lists of Callables #1643

gfldex opened this issue Oct 31, 2017 · 7 comments
Labels
docs Documentation issue (primary issue type)

Comments

@gfldex
Copy link
Contributor

gfldex commented Oct 31, 2017

say (&sin, &cos, &sqrt)».(0.5);
rakudo-moar dcf3e28c5: OUTPUT: «(0.479425538604203 0.877582561890373 0.707106781186548)␤»
@smls
Copy link
Contributor

smls commented Nov 1, 2017

That's not a special construct, but a combination of these features:

  1. ( ) is a postcircumfix operator (documented here)
  2. postcircumfixes may be written in dot notation (documented here)
  3. postcircumfixes can be hypered (not yet documented):
@foo»[0]     # works
@foo».[0]    # works
@foo»{"a"}   # works
@foo».{"a"}  # works
@foo»<a>     # works
@foo».<a>    # works
@foo»()      # does NOT work, for some reason - bug?
@foo».()     # works

No.3 should be documented in operators#Hyper_Operators, which already documents hypered postfix operators and method calls.

(There's also this section, which is a bit dubious because that's not actually an operator as such.)

@tisonkun
Copy link
Member

tisonkun commented Nov 1, 2017

@smls

@foo»(0.5) # does NOT work, for some reason - bug?
turns to, if @foo = [&sin, &cos, &sqrt]
(0.5).CALL-ME(&sin) and so on
so it complains "No such method 'CALL-ME' for invocant of type 'Rat'"

not sure about above, it may be wrong.
a common use of >> is:

sub postfix:<!> ($a) { -$a };

say [1,2,3,4]>>!; # [-1 -2 -3 -4]

However, @foo».(0.5) # works
turns to
&sin.(0.5) and so on

Not a bug I think

@smls
Copy link
Contributor

smls commented Nov 1, 2017

turns to [...] (0.5).CALL-ME(&sin) and so on

Shouldn't it turn into &sin.CALL-ME(0.5)?

Also, it looks like what's currently happening is even weirder:

➜  [&sin, &cos, &sqrt]»( &say );
sub sin ($) { #`(Sub+{is-pure}|93829902580832) ... }sub say (| is raw) { #`(Sub|93829903363016) ... }
sub cos ($) { #`(Sub+{is-pure}|93829902582048) ... }sub say (| is raw) { #`(Sub|93829903363016) ... }
sub sqrt ($) { #`(Sub+{is-pure}|93829902595424) ... }sub say (| is raw) { #`(Sub|93829903363016) ... }

@tisonkun
Copy link
Member

tisonkun commented Nov 1, 2017

@smls
interesting,

> dd [&sin, &cos, &sqrt]»( &say );
sub sin ($) { #`(Sub+{is-pure}|140321546561448) ... }sub say (| is raw) { #`(Sub|140321547176936) ... }
sub cos ($) { #`(Sub+{is-pure}|140321546562664) ... }sub say (| is raw) { #`(Sub|140321547176936) ... }
sub sqrt ($) { #`(Sub+{is-pure}|140321546576040) ... }sub say (| is raw) { #`(Sub|140321547176936) ... }
[Bool::True, Bool::True, Bool::True]

I am going to rakudo to find out how >> works

above seems &sin -> &sin.&say, but what it does is more than that.

@tisonkun
Copy link
Member

tisonkun commented Nov 1, 2017

@smls

https://github.com/rakudo/rakudo/blob/23776247298f24fe374903e5239cdd61f173078a/src/Perl6/Actions.nqp#L7511

take a look at examples below

13:35 | wander | m: sub see-what-pass { dd @; }; [1,2,3]>>( &see-what-pass );
13:35 | camelia | rakudo-moar b386963a3: OUTPUT: «[1, sub see-what-pass (*@
) { #(Sub\|60245232) ... }]␤[2, sub see-what-pass (*@_) { #(Sub|60245232) ... }]␤[3, sub see-what-pass (*@) { #`(Sub|60245232) ... }]␤»
13:37 | wander | m: sub postfix:<!> { dd @
; }; [1,2,3]>>!;
13:37 | camelia | rakudo-moar b386963a3: OUTPUT: «[1]␤[2]␤[3]␤»

so, normally use >> with postfix operator

@tisonkun
Copy link
Member

tisonkun commented Nov 1, 2017

@gfldex I think "doc >>. on lists of Callables" is not so different from examples existing.

see

say (<a b>, <c d e>)».elems;        # OUTPUT: «(2 3)␤» 
say (<a b>, <c d e>)».&{ .elems };  # OUTPUT: «((1 1) (1 1 1))␤» 

but if you find it worth to add new examples, you can do it by yourself and send a PR.

@AlexDaniel AlexDaniel added the docs Documentation issue (primary issue type) label Nov 3, 2017
@tisonkun
Copy link
Member

tisonkun commented Nov 4, 2017

@AlexDaniel , I don't think we have to document ">>. on lists of Callables".

Because it's no more than [obj1, obj2, ...]>>.method

And we may be going to rearrange the doc in a few days, so keep the doc from redundant.

To sum up, this issue can be closed.

@JJ JJ closed this as completed in daee46f Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type)
Projects
None yet
Development

No branches or pull requests

4 participants