Replies: 2 comments
-
No, V doesn't support tuples, just multi-returns of specific types. Your code can be made to work with modifications... fn parse_line() (string, []map[int]string) {
return "Hello", [{1: "World"}, {2: "Hola"}]
} or as a single map fn parse_line() (string, map[int]string) {
return "Hello", {1: "World", 2: "Hola"}
} |
Beta Was this translation helpful? Give feedback.
-
Go has anonymous structs, which would work: fn parse_line() (string, []struct {id int, text string}) {
return "Hello", [{1, "World"}, {2, "Hola"}]
} Although an anonymous struct is longer, it's much clearer for the parser than using parentheses to support a tuple, because parens are also used for expression grouping. Unfortunately if we want to support embedding too, we still have to name the struct fields (or use fn parse_line() struct {text string, line int} {...}
{s, n} := parse_line() |
Beta Was this translation helpful? Give feedback.
-
I was trying to do something like this
I know multi return functions work, how ever it is not clear to me if the function is returning a specific type that can be constructed or is it just syntax sugar and the "tuple" like struct does not really exists? Something like a tuple type could be a really good addition to the lenguaje as a general construct for initializing maps, multi-return functions, composing data without creating a struct, etc.
Beta Was this translation helpful? Give feedback.
All reactions