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

Tips for negation on grep, first, etc. #1425

Closed
colomon opened this issue Jul 26, 2017 · 4 comments
Closed

Tips for negation on grep, first, etc. #1425

colomon opened this issue Jul 26, 2017 · 4 comments
Assignees
Labels
docs Documentation issue (primary issue type)

Comments

@colomon
Copy link

colomon commented Jul 26, 2017

One of the common use cases of grep is to filter against a negative test -- the classic -v option for command line grep. Negation of tests usually results in more complicated tests, and the negation approaches are different for different sorts of tests. A quick guide to handling this, either in the grep documentation or with a pointer from the grep documentation, would be very handy.

@colomon colomon added the docs Documentation issue (primary issue type) label Jul 26, 2017
@coke coke closed this as completed in 513b730 Jul 27, 2017
@AlexDaniel
Copy link
Member

Great.

That said, it seems that people don't necessarily realize why this construct works, which is actually why we have this ticket in the first place. I think we can provide much more value by explaining why it works. See jnthn's explanation, which may be a bit too short for docs but it is a good starting point anyway.

Another interesting point is that we don't really explain how to do not-grep. For example, .grep({!Int}) is not going to work. Therefore I propose to recommend this idiom also:

say <a b c d e f>.grep(none Int)

@AlexDaniel AlexDaniel reopened this Jul 27, 2017
@colomon
Copy link
Author

colomon commented Jul 27, 2017

Yes, while coke++'s documentation change was exactly what I needed this morning, I think Alex is right on both fronts -- a deeper explanation would be nice and a broader explanation would be nice.

@AlexDaniel
Copy link
Member

AlexDaniel commented Jul 27, 2017

OK, here's another very important point: https://irclog.perlgeek.de/perl6/2017-07-27#i_14927558

TL;DR none junction is 8 times faster than using a block.

@AlexDaniel
Copy link
Member

I've submitted this ticket: https://rt.perl.org/Ticket/Display.html?id=131805

Turns out that the difference in 8 times was due to a regression. Also, this is only relevant when you're grepping lists of Ints (and trying to match them with a regex), which is not very common anyway.

none junction is still ≈1.45 times faster if we add ».Str, but this difference is getting close to being irrelevant.

Soooo… I guess none is still worth a mention, even though performance benefits of using it currently no longer seem to be that huge.

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

3 participants