ISibboI / evalexpr

A powerful expression evaluation crate 🦀.
GNU Affero General Public License v3.0
325 stars 54 forks source link

Support get value from tuple #99

Open ogata-k opened 2 years ago

ogata-k commented 2 years ago

I want to get value at the index from a tuple.

e.g. eval("(1,2,3,4).4") // 4

ISibboI commented 2 years ago

That's a nice idea. I am unsure though if I want to implement this as a new syntax or simply as a builtin function.

What do you think about e.g. eval("get((1,2,3,4), 4)") // 4?

ogata-k commented 2 years ago

If I think of it as an array rather than a tuple, I think that such a function notation is better. But, I have never seen such a function notation in a tuple.

However, since I just want to get the value from the tuple, it doesn't matter which one I use.

tsmt09 commented 2 years ago

@ISibboI

Hey, this would be also useful in the project I'm working on. I'm currently thinking about implementing it. Did you already start, if not I will be happy to make another pullrequest for it soon.

ogata-k commented 2 years ago

I'm sorry, I'm thinking about how to implement it, but I can't think of a good one.

tsmt09 commented 2 years ago

for us, it would be also be great to have arrays(vecs) and objects(maps) to be compatible with serde_json some time in future. but I understand that woudl be a loooong way to go and I'm currently happy just having tuples. so I don't dare asking for it, but maybe I will come up with an array and object implementation draft in the future.

That being said, the usual ways of writing it

ISibboI commented 2 years ago

Thank you for your interest in implementing this! I actually thought about the dot notation ((1, 2).0) before, but it was not trivial to implement because the dot is also a decimal separator. So it would mean to refactor also float parsing a little. At the moment I am quite busy, so I would not want to make that non-trivial changes myself. However, I am happy to review and accept pull requests.