Open ogata-k opened 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
?
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.
@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.
I'm sorry, I'm thinking about how to implement it, but I can't think of a good one.
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 reasonableget((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. 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.
I want to get value at the index from a tuple.
e.g.
eval("(1,2,3,4).4") // 4