Python and Ruby both recognize this as valid syntax:
a, b, c = 1, 2, 3
a, b, c = function_call()
The MOO programming language also allows something like this.
--Nick B Fri, 17 Sep 2004 08:25:23 -0400
Yeah, but I was thinking of non-hippy languages...
--Kirk Fri, 17 Sep 2004 10:27:50 -0400
Well, C++ allows pass by reference. It's not as elegant as (a,b,c) = foo(x,y,z), and since there isn't anything visible at the calling level it can get a little confusing. But there are just some times where it's 10x better than mucking around with pointers.
Personally, I prefer to have the return parameter a simple return code, with the actual returned values either passed in as pointers or references.
--ericball Fri, 17 Sep 2004 11:54:20 -0400
Pass-by-reference is how Java is doing it for all non-primitive types, right? If I recall correctly, C++'s reference was mostly a semantic nice-ity, letting you get away from ugly pointer de-referencing in the code...
I guess my problem with your prefered method is that it's just not clear. I tend to assume input parameters are input parameters, and not doing double duty. (of course, that can be a dangerous assumption...)
--Kirk Fri, 17 Sep 2004 12:57:09 -0400
Hurricane Ivan...sigh. What a beautiful hurricane!
--Candi Fri, 17 Sep 2004 15:40:11 -0400
Err....probably more beautiful from an orbiting space station than, say, out the window of your Florida trailer home...
--Kirk Fri, 17 Sep 2004 16:15:14 -0400
the perl you showed is just syntactic sugar for getting things out of the list/array returned by the function. Perl, like Java, can only return one thing, it just makes it easier to look at the components of the list that comes out.
--masukomi Sat, 18 Sep 2004 01:12:35 -0400
I see what you mean in theory, but given how Perl is loosely typed and Java is strongly typed, in practice it's a world of difference. I mean, returning a collection of Object and then casting specific members of that collection is Ugly with a capital-UGH
--Kirk Sat, 18 Sep 2004 01:26:28 -0400
I remember returning multiple values in Assembly (various architectures). Something like: if CF=0 (Carry Flag) then BX contains a pointer to the result, else if CF=1, then AX has an error code. In fact, any number of items (depending upon the architecture) could be easily returned and I sorely missed that in nearly every other language I've used.
But there are other aspects to consider when returning multiple values. Take, for instance, the following (in C):
if (strcmp(a,b) == 0) { }
How would you work that with a function that returns multiple parameters? Leftmost is checked? Rightmost?
And yes, that is a cool picture of Ivan. I have a collectio of Frances when we here in Florida were impatiently awaiting her arrival and while nice, you don't get to see the satellite in question.
--Sean Conner Sat, 18 Sep 2004 04:39:56 -0400
Hm, good point Sean. I would say that for testing multiple return values in place, something like
if(somefunction() == (5,"hey","ho"))
might work...with all primitives tested on == and all objects on .equals , with a "short circuit" operator in place, first it tests the leftmost, and if they're equal, only then does it go on to test the next one, until it finds unequal values or runs out of equal ones...
--Kirk Sat, 18 Sep 2004 09:52:32 -0400
Nobody else is saying it, so I will.
NEEEEEERRRRRRRDS!
--LAN3, a nerd. Sat, 18 Sep 2004 13:37:42 -0400
Alright, master of Unix print queues...
--Kirk Sat, 18 Sep 2004 20:05:57 -0400