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

Is flat another way to say |? Why do we only document one? #892

Closed
shadowcat-mst opened this issue Sep 7, 2016 · 4 comments
Closed

Is flat another way to say |? Why do we only document one? #892

shadowcat-mst opened this issue Sep 7, 2016 · 4 comments
Assignees
Labels
update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc.

Comments

@shadowcat-mst
Copy link

https://docs.perl6.org/language/containers

"Flatteing, items and containers" mentions flat.

> say (flat @foo, 8, 9).elems
5
> say (|@foo, 8, 9).elems
5

seem to be equivalent but there's no mention of the slip syntax

@timo
Copy link
Contributor

timo commented Sep 7, 2016

in an actual call, like say(1, 2, 3) the "flat" will not cause items of the array to become multiple positional parameters. That's why the prefix | ought to also be explained, at the very least in that context with a note pointing from here to there.

@AlexDaniel AlexDaniel added the docs Documentation issue (primary issue type) label Sep 10, 2016
@JJ
Copy link
Contributor

JJ commented Apr 20, 2018

I have the hunch that the "single argument rule" has something to do with them not being the same. But it's true this will have to be documented.

@JJ JJ self-assigned this Apr 20, 2018
@zoffixznet
Copy link
Contributor

zoffixznet commented Apr 20, 2018

There isn't that much similarity between the two, let alone equivalence.

<Zoffix_> m: my @l := 1, 2, (3, 4, (5, 6)), [7, 8, (9, 10)]; say (|@l, 11, 12); say (flat @l, 11, 12)
<camelia> rakudo-moar f6756bb4d: OUTPUT: «(1 2 (3 4 (5 6)) [7 8 (9 10)] 11 12)␤(1 2 3 4 5 6 7 8 (9 10) 11 12)␤»
<Zoffix_> m: my @l := 1, 2; dd ($@l, $@l).flat
<camelia> rakudo-moar f6756bb4d: OUTPUT: «($(1, 2), $(1, 2)).Seq␤»
<Zoffix_> m: my @l := 1, 2; dd ($@l, $@l).map: |*
<camelia> rakudo-moar f6756bb4d: OUTPUT: «(1, 2, 1, 2).Seq␤»
<Zoffix_> m: my @l := 1, 2; dd [flat(@l), flat(@l)]
<camelia> rakudo-moar f6756bb4d: OUTPUT: «[(1, 2).Seq, (1, 2).Seq]␤»
<Zoffix_> m: my @l := 1, 2; dd [|@l, |@l]
<camelia> rakudo-moar f6756bb4d: OUTPUT: «[1, 2, 1, 2]␤»
<Zoffix_> m: my @l := 1, 2; dd [foo => |@l]
<camelia> rakudo-moar f6756bb4d: OUTPUT: «[:foo(slip(1, 2))]␤»
<Zoffix_> m: my @l := 1, 2; dd [foo => @l.flat]
<camelia> rakudo-moar f6756bb4d: OUTPUT: «[:foo((1, 2).Seq)]␤»
<Zoffix_> m: my @l := 1, 2; my %h = foo => |@l; dd [%h<foo>]
<camelia> rakudo-moar f6756bb4d: OUTPUT: «[slip(1, 2),]␤»
<Zoffix_> m: my @l := 1, 2; my %h := foo => |@l; dd [%h<foo>]
<camelia> rakudo-moar f6756bb4d: OUTPUT: «[1, 2]␤»

flat

  • Creates a Seq that's generated by flattening all non-containerized Iterables, which includes the contents of such Iterables; all the way until they're entirely flattented or you descend up to a containerized Iterable
prefix:<|>
  • Creates a Slip. That's it. The rest of the observed behaviour is the behaviour of Slips, not of prefix:<|>, and that behaviour causes only the given Iterable to be flattened into the containing Iterable and that won't occur if the Slip is containerized

(this doesn't comment on the | used in to flatten argument lists, which has nothing at all to do with Slips at all and is a special-cased compiler feature).

@JJ
Copy link
Contributor

JJ commented Apr 20, 2018

I'll try to summarize that and improve the documentation in that area.

@JJ JJ added update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc. and removed docs Documentation issue (primary issue type) labels Apr 20, 2018
@JJ JJ closed this as completed in 2621399 May 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc.
Projects
None yet
Development

No branches or pull requests

5 participants