3 ms·
I'm new to Go- but I don't think it has tuples in the python sense[1]. Happy to be corrected here if there's a broader definition you're referring to. I do wis
by leetrout 11y ago
I'm new to Go- but I don't think it has tuples in the python sense[1]. Happy to be corrected here if there's a broader definition you're referring to.
I do wish it had support for slice unpacking like it does for return values. The assignment from returns or ranges is one of the things I really ejoy.
Edit: [1] I'll clarify that I define that as an immutable, indexable data structure that you can unpack in to multiple assignments.
- nv-vn 11y agoIt doesn't have "true tuples" but you can do multiple returns in a tuple-like way and there is syntax for unpacking it. While a pair can't be stored in a single variable, you can just manually unpack and repack them for a similar effect to what tuples can do. For the record, most languages don't have indexable tuples as far as I'm aware and make you unpack them with some form of pattern matching.
- pcwalton 11y ago> For the record, most languages don't have indexable tuples as far as I'm aware Most languages with tuples have indexable tuples either via language syntax or library functions. (For example, OCaml practically does, with fst and snd.) > It doesn't have "true tuples" but you can do multiple returns in a tuple-like way and there is syntax for unpacking it. There's a large difference between having multiple return values and having first-class tuple values.
- nv-vn 11y agoHaskell/OCaml style "fst" and "snd" functions can't index arbitrary tuples (they only work on 2-tuples/pairs): http://i.imgur.com/PbhNxmu.png http://i.imgur.com/PbhNxmu.png.