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

Fix reduce builtin #2925

Merged
merged 1 commit into from
Nov 1, 2023
Merged

Fix reduce builtin #2925

merged 1 commit into from
Nov 1, 2023

Conversation

erik-adelbert
Copy link
Contributor

#2880 introduced a buggy reduce builtin which operates on the given list from right to left. So this:

reduce(lambda x, y: ''.join((x, y)), ["a", "b", "c", "d", "e"])

incorrectly returns "edcba" instead of "abcde".

The proposed patches hopefully solve this bug.

Copy link
Member

@Tatskaari Tatskaari left a comment

Choose a reason for hiding this comment

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

Thanks! This definitely wasn't intentional. Looks like the Python one is left associative which is inline with this change.

@@ -186,11 +186,11 @@ <h2 class="title-2" id="python-builtins">
<span>
<code class="code"
><span class="fn-name">reduce</span><span class="fn-p">(</span
><span class="fn-arg">function</span>, <span class="fn-arg">seq</span
><span class="fn-arg">reducer</span>, <span class="fn-arg">seq</span
Copy link
Member

Choose a reason for hiding this comment

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

This was copied from here:
https://docs.python.org/3/library/functools.html#functools.reduce

Looks like you've changed the arg name as well which makes it inconsistent with Python if I understand correctly. Should we switch this back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right now it is in line with its neighbours in please code but yes we can make it in line with python instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please/docs/lexicon.html

Lines 177 to 181 in 8d9ffe8

<code class="code"
><span class="fn-name">map</span><span class="fn-p">(</span
><span class="fn-arg">mapper</span>, <span class="fn-arg">seq</span
><span class="fn-p">)</span></code
>

@Tatskaari Tatskaari merged commit 22f0242 into thought-machine:master Nov 1, 2023
5 checks passed
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.

2 participants