Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hai prog: multiple return values

Name: Anonymous 2009-10-02 19:31

Hello

I know one can use pass-by-reference for getting multiple values back from a function, but is there a language that allows you to actually define multiple outputs seperate from the parameter list for super neatness.

I was thinking it would be super-cool to have an auto-defined struct based on the function return values. so in some pseudo-language it would be like...


def splitstring  string<s char<sep string>a string>b

s = "hello world"

splitstring s ' '

printf(splitstring.a)
printf(splitstring.b)


would that be totally kawaii aewsome?

obviously each thread would have its only instances of these auto-structs.

Name: Anonymous 2009-10-04 21:07

>>1
This is a bad idea. It will only confuse things when real programs are to be written. Perhaps it would be a good addition to a toy language, but not a real one. When you call a function, you want to know what the fuck it's returning. Also, if you have some function return two values in (with your proposed idea), then what happens if one of the values depends on the other? It makes it hard as fuck to debug.
It may look like this:

f(x)
{
   int a
   modify a
   IF WE'RE RETURNING FIRST RETURN VALUE:
      return a

   b = modified a
   IF WE'RE RETURNING SECOND RETURN VALUE:
      return b
}

One can imagine how hard it would be to debug this when the function gets large. So it's a bad idea because people will write large, unclear function and code will be harder to debug.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List