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

indexing support #140

Closed
tekjar opened this issue Nov 22, 2017 · 7 comments
Closed

indexing support #140

tekjar opened this issue Nov 22, 2017 · 7 comments

Comments

@tekjar
Copy link

tekjar commented Nov 22, 2017

Hi. Is there a way to pass list variables and use indexes?

byte[] bytes
new Expression("bytes[1] + bytes[2]")
@uklimaschewski
Copy link
Collaborator

Sorry, there is no support for arrays

@RobertZenz
Copy link
Collaborator

But could there be? I mean, the though is intriguing but I do not know if the [] is already taken with some other operation.

Maybe in the first step just being able to define arrays and use their values might be interesting, something like this:

Expression expression = new Expression("values[0] + values[1]");
expression.with("values", new BigDecimal[] { BigDecimal.valueOf("5"), BigDecimal.valueOf("7") });
// Or with varargs:
expression.with("values", BigDecimal.valueOf("5"), BigDecimal.valueOf("7"));

Without any sort of "array operations".

@uklimaschewski
Copy link
Collaborator

Array indexes (like, e.g. value[0]) could be seen as functions. The parser/tokenizer, shunting yard routine and evaluator could be extended to support this with a reasonable efford, I think.
Then even expression like "a + values[x - 1]" would be possible.
But what would it be good for? You need some more array functionality (loops, assignments, calculations etc.)
Else you can still go with defining a variable for each "array" value, "value1", "value2" etc.
I am not seeing the real need for it right now, but maybe you have some examples?

@RobertZenz
Copy link
Collaborator

Mh, I ain't got good usage examples without array operations (I didn't think beyond basic math operations, though), I was just throwing ideas into the room. Maybe @tekjar got some.

@tekjar
Copy link
Author

tekjar commented Nov 22, 2017

@uklimaschewski @RobertZenz My use case is also basic math equations but my array size is dynamic. So It's difficult to create variables for each array value

@uklimaschewski
Copy link
Collaborator

I marked this issue as an enhancement, maybe there will be something in the future. Simple one-dimensional arrays would not be enough, I think.

@uklimaschewski
Copy link
Collaborator

Arrays now supported in version 3.

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

No branches or pull requests

3 participants