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

General issue of abaplint with FOR...IN... ? Scrabble Score #195

Closed
mickrig opened this issue Sep 22, 2022 · 10 comments
Closed

General issue of abaplint with FOR...IN... ? Scrabble Score #195

mickrig opened this issue Sep 22, 2022 · 10 comments
Assignees

Comments

@mickrig
Copy link

mickrig commented Sep 22, 2022

It seems there is a general issue using FOR...IN... maybe only in combination with REDUCE.
Can you please check the issue?
2022-09-22 07_38_32-Exercism_Scrabble Score

In my local environment the code works well.

    DATA letter TYPE c.
    DATA offset TYPE i.
    DATA char_tab TYPE STANDARD TABLE OF c WITH EMPTY KEY.

    DO.
      TRY.
          letter = substring( val = input
                              off = offset
                              len = 1 ).
          offset += 1.
          APPEND to_upper( letter ) TO char_tab.

        CATCH cx_sy_range_out_of_bounds.
          EXIT.
      ENDTRY.
    ENDDO.

    result = REDUCE i(
      INIT score TYPE i
      FOR char IN char_tab
      NEXT score = score + COND #(
                     WHEN matches( val = char pcre = `[AEIOULNRST]` )
                       THEN 1
                     WHEN matches( val = char pcre = `[DG]` )
                       THEN 2
                     WHEN matches( val = char pcre = `[BCMP]` )
                       THEN 3
                     WHEN matches( val = char pcre = `[FHVWY]` )
                       THEN 4
                     WHEN matches( val = char pcre = `[K]` )
                       THEN 5
                     WHEN matches( val = char pcre = `[JX]` )
                       THEN 8
                     WHEN matches( val = char pcre = `[QZ]` )
                       THEN 10 ) ).
@larshp
Copy link
Member

larshp commented Sep 22, 2022

thanks

at first sight I think its an issue with "pcre", try using old style "regex" instead in matches

https://github.com/abaplint/transpiler/blob/main/packages/runtime/src/builtin/matches.ts
https://github.com/abaplint/transpiler/blob/main/test/builtin/matches.ts

@mickrig
Copy link
Author

mickrig commented Sep 22, 2022

Hi Lars, thanks for your feedback. But as you can see on the screenshot I provided there is no issue regarding matches.
I got the same error without using matches in my other reported issue.

@larshp
Copy link
Member

larshp commented Sep 22, 2022

okay rename variable "char" to something else, it is a reserved keyword in JavaScript, which is the runtime. In the future it will automatically workaround this restriction

@larshp
Copy link
Member

larshp commented Sep 22, 2022

I dont see the screenshot, here is a screenshot of the broken screenshot,

image

@larshp
Copy link
Member

larshp commented Sep 22, 2022

after renaming,

image

  METHOD score.
    DATA letter TYPE c.
    DATA offset TYPE i.
    DATA char_tab TYPE STANDARD TABLE OF c WITH EMPTY KEY.

    DO.
      TRY.
          letter = substring( val = input
                              off = offset
                              len = 1 ).
          offset += 1.
          APPEND to_upper( letter ) TO char_tab.

        CATCH cx_sy_range_out_of_bounds.
          EXIT.
      ENDTRY.
    ENDDO.

    result = REDUCE i(
      INIT score TYPE i
      FOR foo IN char_tab
      NEXT score = score + COND #(
                     WHEN matches( val = foo pcre = `[AEIOULNRST]` )
                       THEN 1
                     WHEN matches( val = foo pcre = `[DG]` )
                       THEN 2
                     WHEN matches( val = foo pcre = `[BCMP]` )
                       THEN 3
                     WHEN matches( val = foo pcre = `[FHVWY]` )
                       THEN 4
                     WHEN matches( val = foo pcre = `[K]` )
                       THEN 5
                     WHEN matches( val = foo pcre = `[JX]` )
                       THEN 8
                     WHEN matches( val = foo pcre = `[QZ]` )
                       THEN 10 ) ).
  ENDMETHOD.

@larshp
Copy link
Member

larshp commented Sep 22, 2022

abaplint/transpiler#883

@larshp larshp self-assigned this Sep 22, 2022
@larshp
Copy link
Member

larshp commented Sep 22, 2022

now better error message,
image

@larshp
Copy link
Member

larshp commented Sep 22, 2022

and using regex,
image

@larshp larshp assigned mickrig and unassigned larshp Sep 22, 2022
@larshp
Copy link
Member

larshp commented Sep 22, 2022

try again

its not perfect, but better. Helping with fixes is welcome.

Currently I'm trying to not have totally misleading error messages, and getting code run with correct results

@mickrig
Copy link
Author

mickrig commented Sep 23, 2022

Thanks Lars, with the provided corrections the code works now on exercism. Thanks.

@mickrig mickrig closed this as completed Sep 23, 2022
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

2 participants