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

Adds a PPC for any and all as built-in operator syntax #50

Merged
merged 3 commits into from
Nov 22, 2024

Conversation

leonerd
Copy link
Contributor

@leonerd leonerd commented Jul 17, 2024

A reminder on the PPC process: Accepting this PR means we like the document, but it does not automatically imply that we accept the idea embodied by it. Accepting the document first is useful as it gives it a number and allows us to discuss and iterate on one canonical version of it, ahead of accepting the underlying idea. It is perfectly fine to accept the document even if questions and issues still surround it.


These operators are similar to `grep` in scalar context, though yield a simple boolean truth value relating to how many input values made the filter block yield true. `any` yields true when its block yields true for at least one of its input values, or false if they all yield false. `all` yields true only if every input value makes the block yield true, or false if at least one yields false.

A consequence of these rules is what happens when given an empty list. A call to `any` with an empty list does not have any input values which made the block return true, so its result is false. Conversely, a call to `all` with an empty list does not have any input values which made the block return false, so its result is true.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was at first surprised by this behavior, that all would be true on an empty list; though i did see that that's how every works in javascript and all in python, and i suppose it makes sense. I think we could have a word on why this design choice makes sense from a user's perspective rather than just the implementation reason.

@book
Copy link
Contributor

book commented Nov 21, 2024

Why guard them by a feature, instead of adding them as builtin (and adding them to a later builtin version bundle)?

@Leont
Copy link

Leont commented Nov 21, 2024

Why guard them by a feature, instead of adding them as builtin (and adding them to a later builtin version bundle)?

Because these aren't quite normal functions, the same way grep isn't.

@Grinnz
Copy link

Grinnz commented Nov 21, 2024

When builtin was being designed, at one point a second "keywords" namespace was proposed (possibly by me) for keywords that may have unique parsing behavior. But feature handles these just fine as long as we don't mind the extra feature proliferation.

@book
Copy link
Contributor

book commented Nov 21, 2024

Thanks @Leont and @Grinnz for the explanation.

@book book merged commit 8f45fec into Perl:main Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants