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

Behavior of reduce2 when ind argument is empty vs docstring #1545

Open
sogaiu opened this issue Jan 17, 2025 · 0 comments
Open

Behavior of reduce2 when ind argument is empty vs docstring #1545

sogaiu opened this issue Jan 17, 2025 · 0 comments

Comments

@sogaiu
Copy link
Contributor

sogaiu commented Jan 17, 2025

The current docstring for reduce2 states:

The 2-argument version of reduce that does not take an initialization value. Instead, the first element of the array is used for initialization.

My reading of this is that it leaves unspecified what to do when ind is empty.

According to this commit, the current behavior of returning nil is intentional:

(reduce2 + [])
# =>
nil

It seems like there are at least two other reasonable ways to handle an empty ind argument:

  1. Raise an error
  2. Try to call the f argument with zero arguments

It seems that approach 2 is what Common Lisp went for [1].

If the current behavior is the most desirable, may be it would make sense to update the docstring?


[1] See this comment for more details.

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

No branches or pull requests

1 participant