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

Add ability to clear variables in expression #53

Closed
wants to merge 1 commit into from

Conversation

amila
Copy link

@amila amila commented Jan 13, 2016

Hi,

I just wanted to contribute a very simple change. I wanted to provide the client side to be able to clear the variables set or if a map is passed in to clear the old state.

I have a process that cycles through a series of expressions against different maps with different variables and values.
eg:
expressions = {
expression 1: a + b
expression 2: x - y
}

I have a list of maps with different values:
maps = {
map1: a->1, b->2,
map2: x>5, y->2
}
expression1.setVariables(map1);
expression1.validate(true); will return a true, which is correct!
If immediately after I do expession1.setVariables(map2) this will also return a true, which is incorrect as map2 has variables x and y and not a and b. It returns true because the expression has state with regards to the variables.

For the reason I mentioned above I suggest a clearing of the data. I hope you find this contribution of some benefit to you.

Thanks,
Sajith

@fasseg
Copy link
Owner

fasseg commented Apr 18, 2016

Hey Sajith,

Adding a method to clear the variables is possible and makes sense, but clearing the variables in the setVariables(Map) call is not possible. This is an API Change and will break existing software using exp4j.

@shuvamc019 shuvamc019 closed this Sep 12, 2019
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.

3 participants