wait why are multiple returns a big deal? Isn't it essentially returning a tuple?

am confus
@hyphen ABIs also generally support returning multiple values, the only reason a language wouldn't support it is C-abooism
@tuxcrafting i mean i genuinely don't know if multiple returns is some hard big brain sophisticated concept that I'll get laughed at for daring to think it's just tuples, or if it's just a fancy way of saying the language has first-class tuples and pattern matching on them.
@hyphen @tuxcrafting it's not a tuple. think about it in assembler.

tuples are just the workaround some people use when a language lacks features
@fluffy @tuxcrafting (adding @r )
You both say tuples are a workaround but I fail to see the distinction. If I am thinking in assembly. I would be returning a pointer to a contiguous chunk of memory that has the values. So uh, a tuple.
@hyphen @fluffy @tuxcrafting When you ask "Is this part of the language?", the answer for the actual multi return would be yes. But for tuples, it would be no, because tuples are high lever data structure and are implemented using the language but are not part of the language.
But then again the question is "does it matter?" and I think you're right, it doesn't. I found this[1] very interesting article. In C++, the compiler treats the tuple values in a special way, they more or less work the same way as the multi value returns. Each tuple value gets pushed to the stack/register independently instead of just the address of the tuple descriptor (if there is any, I don't know C++ that well). I'm not sure how other languages implement them, but yeah, in C++ they're essentially same as multi value return.

[1] https://dr-knz.net/measuring-multiple-return-values-in-go-and-cpp.html
Follow

@r technically that optimization is not specific to tuples, it would treat any type that way. From language feature point of view you can call a function with a tuple as the parameters with std::apply, and if the function returns a tuple you can decompose it in place
auto [x, y] = func();
In general any type can work this way if you make it tuple-like by specializing a couple of standard templates for it. That said the tuple itself is way more powerful and important than any of that syntax sugar.

this post was made by c++ gang (now that has got to be a real gang)
@hyphen @tuxcrafting @fluffy

· · SubwayTooter · 1 · 0 · 2
@namark @r @tuxcrafting @fluffy ah yes, the two stupidly crazy optimizing compilers I always have no idea what they're doing: g++ and GHC

@hyphen *looks up GHC*
"it can make c code and send it to gcc
or compile to binary itself
or use an llvm backend"

reaction:
hehe, of cource it uses gcc
or whaaa? cool
or blasphemy!

@tuxcrafting @r @fluffy

@namark @tuxcrafting @r @fluffy whaaat... You know Mercury but have no idea what the Haskell compiler is? Strange :cirnoSip:

Anyway GHC stopped doing C transpilation very very early on in its development. It uses its own typed AST representation, then a GHC Core lang (a variant of System FC), then its IR, the STG, which is passed on many times for moar optimization. Then finally the assembly codegen.
Before those transformations there's the parsing and desugaring and type-checking.
Somehow it still manages to compile faster than g++ still xD

@hyphen
nothing can beat g++ in slow! It gives you time to think about what you have done, and be ashamed.

I wish I knew mercury, maybe then it would stop calling my code non-deterministic ToT

@tuxcrafting @r @fluffy

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.