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

Support get value from tuple #99

Open
ogata-k opened this issue Mar 8, 2022 · 6 comments
Open

Support get value from tuple #99

ogata-k opened this issue Mar 8, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@ogata-k
Copy link

ogata-k commented Mar 8, 2022

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

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

@ISibboI ISibboI added the enhancement New feature or request label Mar 12, 2022
@ISibboI
Copy link
Owner

ISibboI commented Mar 12, 2022

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
Copy link
Author

ogata-k commented Mar 12, 2022

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
Copy link

tsmt09 commented Jul 21, 2022

@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
Copy link
Author

ogata-k commented Jul 21, 2022

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

@tsmt09
Copy link

tsmt09 commented Jul 21, 2022

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

  • (1,2,3,4)[2] - i would not like because I would save it for future array implementations
  • (1,2,3,4).2 - seems reasonable
  • get((1,2,3,4),4) - also a good way. maybe it would make sense to call it tuple::get the same way theres math:: and str:: functions. then, tuple::set would also make sense of course.

@ISibboI
Copy link
Owner

ISibboI commented Jul 22, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants