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

map_with_index & if then (without else) is broken #8441

Closed
JaroslavTulach opened this issue Dec 3, 2023 · 5 comments
Closed

map_with_index & if then (without else) is broken #8441

JaroslavTulach opened this issue Dec 3, 2023 · 5 comments
Assignees

Comments

@JaroslavTulach
Copy link
Member

While working on Dec 3 I realized we have problem with iterating over vectors. The following loops shall behave the same, right? With or without y being present. But they don't!

collect_digits around digits =
    b = Vector.new_builder
    digits.map_with_index y-> row->
        last = row.characters.fold_with_index "" current-> x-> ch->
            case ch of
                '.' ->
                    if current.at 0 == " " then b.append current.trim
                    ""
                digit ->
                    (if around.at y . at x then " "+current else current) + digit
        if last.at 0 == " " then b.append last.trim
    b.to_vector

The program behaves differently with or without following change:

diff --git src/Main.enso src/Main.enso
index b99008b..f60877d 100644
--- src/Main.enso
+++ src/Main.enso
@@ -33,7 +33,6 @@ collect_digits around digits =
                 digit ->
                     (if around.at y . at x then " "+current else current) + digit
         if last.at 0 == " " then b.append last.trim
-        y
     b.to_vector
 
 main =
@JaroslavTulach
Copy link
Member Author

The sample Dec_03.zip project. Unzip and run:

$ enso-engine-0.0.0-dev-linux-amd64/enso-0.0.0-dev/bin/enso --run Dec_03/
540025

Remove y line 36 and execute again:

$ enso-engine-0.0.0-dev-linux-amd64/enso-0.0.0-dev/bin/enso --run Dec_03/
4028

Very disturbing.

@enso-bot
Copy link

enso-bot bot commented Dec 19, 2023

Pavel Marek reports a new STANDUP for today (2023-12-19):

Progress: - Looking into the bug with map_with_index and if_then.

  • Comming up with a smaller reproducer.
  • Seems like a problem when if_then's condition is profiled on dataflow error?
  • Looking into the problems with TestLogProvider service lookup in project-manager tests - All unit tests use the same testing logging provider #8593 It should be finished by 2023-12-22.

@Akirathan Akirathan moved this from 📤 Backlog to ⚙️ Design in Issues Board Dec 20, 2023
@Akirathan
Copy link
Member

This is a smaller reproducer, it is an excerpt from the original Dec_03.zip:

from Standard.Base import all

collect_digits around digits =
    b = Vector.new_builder
    digits.map_with_index y-> row->
        last = row.characters.fold_with_index "" current-> x-> ch->
            case ch of
                '.' ->
                    if current.at 0 == " " then b.append current.trim
                    ""
                digit ->
                    (if around.at y . at x then " "+current else current) + digit
        if last.at 0 == " " then b.append last.trim
        #Nothing
    b.to_vector

main =
    around_small = [[False, False, False, False, False, True, True, True, False, False, False, False, False, False, True, True, True, False, False, False], [False, False, False, False, False, True, True, True, False, False, False, False, False, False, True, True, True, False, False, False]]
    num_small = [".......12.......935.", "............968....."]
    res = collect_digits around_small num_small
    IO.println <| "res.length = " + res.length.to_text

With the commented 14th line (#Nothing), the result is 2, but when uncommenting, the result is 3.

This doesn't look like a bug to me. Then if last.at 0 == "" then b.append last.trim behaves as expected. The thing is that the expression last.at 0 results in an Index_Out_Of_Bounds.Error, and so a dataflow error is returned, instead of Nothing.

@Akirathan
Copy link
Member

Closing this as not an issue.

@github-project-automation github-project-automation bot moved this from ⚙️ Design to 🟢 Accepted in Issues Board Dec 22, 2023
@JaroslavTulach
Copy link
Member Author

last.at 0 results in an Index_Out_Of_Bounds.Error, and so a dataflow error is returned, instead of Nothing

OK, thank you for your investigation, Pavel.

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

No branches or pull requests

2 participants