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

Beer Song - Error buildCondBody, unexpected expression #68

Closed
jung-thomas opened this issue Feb 10, 2022 · 7 comments
Closed

Beer Song - Error buildCondBody, unexpected expression #68

jung-thomas opened this issue Feb 10, 2022 · 7 comments
Assignees

Comments

@jung-thomas
Copy link
Collaborator

I was working through the Beer Song exercise. I built a solution that runs and passes the tests in an ABAP backend system (ABAP on SAP BTP Free Trial).
image

But when I run the same solution in Exercism in the Web Editor I receive the error: Error buildCondBody, unexpected expression
image

Here's the source code that I'm using for this exercise:

    result = VALUE string_table(
      FOR i = 0 UNTIL i = take_down_count
      (
         COND string(
         LET current_count = initial_bottles_count - i
             new_count = current_count - 1
          IN
          WHEN current_count = 1 THEN |{ current_count } bottle of beer on the wall, { current_count } bottle of beer.|
          WHEN new_count <= 0 THEN |No more bottles of beer on the wall, no more bottles of beer.|
          ELSE  |{ current_count } bottles of beer on the wall, { current_count } bottles of beer.|
          )
      )
      (
         COND string(
         LET current_count = initial_bottles_count - i
             new_count = current_count - 1
          IN
          WHEN current_count = 2 THEN |Take one down and pass it around, 1 bottle of beer on the wall.|
          WHEN current_count = 1 THEN |Take it down and pass it around, no more bottles of beer on the wall.|
          WHEN new_count <= 0 THEN |Go to the store and buy some more, 99 bottles of beer on the wall.|
          ELSE |Take one down and pass it around, { new_count } bottles of beer on the wall.|
          )
      )
      ( ||
      )
    ).
    DELETE result INDEX lines( result ).
@larshp
Copy link
Member

larshp commented Feb 11, 2022

thanks, will have a look, fixing one bug at a time, take one down...

@larshp
Copy link
Member

larshp commented Mar 24, 2022

this scenario/code is a bit difficult, since it reuses the LET variable names

@pokrakam
Copy link
Collaborator

pokrakam commented Apr 4, 2022

@larshp wouldn't it help to do the same as ABAP does behind the scenes and convert a let to a procedure-level data?

@larshp
Copy link
Member

larshp commented Apr 4, 2022

thats what it does for each LET, but it doesnt work in above as there are two lets reusing the same name

@pokrakam
Copy link
Collaborator

That's what I meant, no need to declare if it already exists.
ABAP issues an error if you use two LETs with different data types though, so I guess that part may be tricky. I've encountered this behaviour before so here are the different ways ABAP reacts to LET:

OK:

data(v1) = conv string( let f = 1 in f ).

OK:

data(v1) = conv string( let f = 1 in f ).
data(v2) = conv string( let f = 1 in f ).

NOK:

data f type i.
data(v1) = conv string( let f = 1 in f ).

NOK:

data(v1) = conv string( let f = 1 in f ).
data(v2) = conv string( let f = 'A' in f ).

This last one leads to: "F" was already declared with the type "I" and cannot be used with the type "C" here.

@larshp
Copy link
Member

larshp commented Nov 8, 2022

@jung-thomas try again

image

@larshp larshp assigned jung-thomas and unassigned larshp Nov 8, 2022
@jung-thomas
Copy link
Collaborator Author

Yes works now. Thanks.

This issue was closed.
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

4 participants