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

Can't define custom flat prefix op with pipe #4328

Closed
p6rt opened this issue Jun 17, 2015 · 6 comments
Closed

Can't define custom flat prefix op with pipe #4328

p6rt opened this issue Jun 17, 2015 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Jun 17, 2015

Migrated from rt.perl.org#125427 (status was 'resolved')

Searchable as RT125427$

@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

From @labster

07​:02 labster m​: multi sub prefix​:<|> (\a) { a.flat }; say
(|[1,2,3]).perl
07​:02 camelia rakudo-moar d6430c​: OUTPUT«5===SORRY!5=== Error while
compiling /tmp/jvrQI4RBsS␤Arg-flattening | is only valid in an argument
list␤at /tmp/jvrQI4RBsS​:1␤------> 3i sub prefix​:<|> (\a) { a.flat }; say
(|7⏏5[1,2,3]).perl␤»

Expected, one of​:
A) single pipe works as shorthand for flat outside of arg list
B) Rakudo allows me to define my own flat operator (though, in this case,
prefix​:<|||> does work)

Maybe this should be notabug, but if so I'd like an explanation as to why
neither A nor B should work.

@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

From @pmichaud

On Tue, Jun 16, 2015 at 09​:28​:28PM -0700, Brent Laabs wrote​:

07​:02 labster m​: multi sub prefix​:<|> (\a) { a.flat }; say
(|[1,2,3]).perl
07​:02 camelia rakudo-moar d6430c​: OUTPUT«5===SORRY!5=== Error while
compiling /tmp/jvrQI4RBsS␤Arg-flattening | is only valid in an argument
list␤at /tmp/jvrQI4RBsS​:1␤------> 3i sub prefix​:<|> (\a) { a.flat }; say
(|7⏏5[1,2,3]).perl␤»

Expected, one of​:
A) single pipe works as shorthand for flat outside of arg list
B) Rakudo allows me to define my own flat operator (though, in this case,
prefix​:<|||> does work)

Maybe this should be notabug, but if so I'd like an explanation as to why
neither A nor B should work.

Unary | already has a defined syntactic meaning in Perl 6 (argument
list interpolation -- see S06 / Flattening argument lists).

In Rakudo unary | is a syntactic construct that can't be overloaded.

So, notabug. :)

Pm

@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

From @pmichaud

On Wed, Jun 17, 2015 at 12​:24​:04AM -0500, Patrick R. Michaud wrote​:

In Rakudo unary | is a syntactic construct that can't be overloaded.

So, notabug. :)

More directly to the comment about unary | possibly working outside of
argument lists, I'm not sure we want to enable the case where unary-|
means something very different outside of an argument list than in it.
I suspect it could be made to do so, however, in which case (| ... )
would be a valid flattening syntax. But I see significant confusion
potential here, which is perhaps best avoided.

Pm

@p6rt
Copy link
Author

p6rt commented Jun 19, 2015

From @jnthn

On Tue Jun 16 22​:24​:27 2015, pmichaud wrote​:

On Tue, Jun 16, 2015 at 09​:28​:28PM -0700, Brent Laabs wrote​:

07​:02 labster m​: multi sub prefix​:<|> (\a) { a.flat }; say
(|[1,2,3]).perl
07​:02 camelia rakudo-moar d6430c​: OUTPUT«5===SORRY!5=== Error
while
compiling /tmp/jvrQI4RBsS␤Arg-flattening | is only valid in an
argument
list␤at /tmp/jvrQI4RBsS​:1␤------> 3i sub prefix​:<|> (\a) { a.flat };
say
(|7⏏5[1,2,3]).perl␤»

Expected, one of​:
A) single pipe works as shorthand for flat outside of arg list
B) Rakudo allows me to define my own flat operator (though, in this
case,
prefix​:<|||> does work)

Maybe this should be notabug, but if so I'd like an explanation as to
why
neither A nor B should work.

Unary | already has a defined syntactic meaning in Perl 6 (argument
list interpolation -- see S06 / Flattening argument lists).

In Rakudo unary | is a syntactic construct that can't be overloaded.

So, notabug. :)

Agree "notabug" in that sense. However, we can always go above and beyond that and note that such a thing will never work out. Now it does this​:

$ perl6-m -e "multi sub prefix​:<|> (\a) { a.flat }"
===SORRY!=== Error while compiling -e
Cannot override prefix operator '|', as it is a special form handled directly by the compiler
at -e​:1
------> sub prefix​:<|><HERE>($x) { }

Tested in S32-exceptions/misc.t.

@p6rt p6rt closed this as completed Jun 19, 2015
@p6rt
Copy link
Author

p6rt commented Jun 19, 2015

@jnthn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant