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

Multiple return values

Name: Anonymous 2018-09-12 18:11

I've always found it weird that a function can take multiple arguments, but it can only return a single value. I guess you can make an Object array, and use that as a hacky workaround to return multiple values (of different data types instead of them all being the same, i.e. int[]).
https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html
What are your thoughts on having return values of different data types?

Functional programming apparently does away with return statements entirely, what's up with that?

Name: Anonymous 2018-09-14 2:33

>>3
Not sure what OOP has to do with this.
A function with multiple arguments, say \(f = \lambda x, y. x + y\) (or \(f(x, y) = x + y\)) is basically the same as \(f = \lambda x. \lambda y. x + y\)
Considering that every function takes a single argument, and that the so called multi-argument functions are simply nested functions, one can see why you can't directly return multiple values.

but it'd be cool if you could return separate things instead of the superclass array workaround
I am far from a Java expert but I am pretty sure that you can just make something like
class Tuple<A, B> { public A fst; public B snd; }
Which is type safe (as far as type-safety in Java goes).

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