Skip to content

Fix expressions with multiple operators. #12

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

Merged
merged 5 commits into from
Dec 21, 2021

Conversation

re-masashi
Copy link
Contributor

Expressions such as 1 +2; or 300*200 work, but expressions which have multiple operations do not work. For example: 1+2+3+4 does not work, and has to be put in a chain of parentheses to get it to work. The other valid expressions are getting evaluated to the value of the first operator, for instance, 1*2*3 becomes 2, by evaluating 1*2 and so on.
This can be solved by adding a loop, converting the first two expressions into lhs and continuing until there are no more pairs.

Expressions such as ``1 +2;`` or ``300*200`` work, but expressions which have multiple operations do not work. For example: ``1+2+3+4`` does not work, and has to be put in a chain of parentheses to get it to work. The other valid expressions are getting evaluated to the value of the first operator, for instance, ``1*2*3`` becomes 2, by evaluating 1*2 and so on.
This can be solved by adding a loop, converting the first two expressions into ``lhs`` and continuing until there are no more ``pair``s.
@ehsanmok
Copy link
Owner

ehsanmok commented Dec 9, 2021

Thanks! this was left as an exercise :) please add some tests to test your changes.

Fixed mistake in making assertion of ``1 + 2 +3 == 2+2+3``
Yet another attempt to make rustfmt happy.
@re-masashi
Copy link
Contributor Author

re-masashi commented Dec 20, 2021

I really apologise for this series of fails. This time I tested it with cargo fmt --all -- --check on my machine and it showed no errors.

Thanks! this was left as an exercise :) please add some tests to test your changes.

I just want to know if you plan to merge this change or do you want to include it in some "solutions" section in the book as it was an exercise.

@ehsanmok
Copy link
Owner

It's great now! thanks :)

@ehsanmok ehsanmok merged commit 86abfb4 into ehsanmok:master Dec 21, 2021
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