# Multiple return and parallel assignement

**URL:** <https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537>\
**Category:** ruby-talk\
**Created:** [20 May 2005 15:31 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537 "2005-05-20T15:31:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Mahurin1](https://avatars.discourse-cdn.com/v4/letter/e/34f0e0/32.png) [@Eric\_Mahurin1](https://rubytalk.org/u/Eric_Mahurin1)\
**Post date:** [20 May 2005 15:31 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/1 "2005-05-20T15:31:51Z")

</div>

yep. return 1,2 and return [1,2] work the same. Also when the  
RHS or LHS of an assign is only single item and the other side  
is multiple items you can think of that single item being  
splatted (\*):

a = 1,2 # \*a = 1,2 # a = [1,2]  
a,b = [1,2] # a,b = \*[1,2] # a,b = 1,2

I've never quite understood why most languages inherently  
support returning only a single value (Ruby uses an array to  
make it look like multiple return values). Multiple return  
values could have been passed back to the caller on the stack  
just like arguments were passed to it. Maybe Ruby also uses an  
array to implement multiple arguments. For Ruby, it really  
doesn't matter too much since we have some niceties (splatting  
and multiple assign) that give you the similar functionality as  
true multiple return values. You can't differentiate between  
something returning a single array and something returning  
multiple values, but I don't think that is a big deal.

Yahoo! Mail  
Stay connected, organized, and protected. Take the tour:  
[http://tour.mail.yahoo.com/mailtour.html](http://tour.mail.yahoo.com/mailtour.html)

> **···**
>
> --- James Britt \<james\_b@neurogami.com\> wrote:
> 
> > James Edward Gray II wrote:  
> > \> On May 20, 2005, at 8:05 AM, jean wrote:  
> > \>  
> > \>\> What do you think about? (Perhaps I don't know enough Ruby  
> > and there is  
> > \>\> a way to do the same thing in Ruby 😉 )  
> > \>\>  
> > \>\> Thinking at Ruby I'd like that if I call mymethod defined  
> > above with  
> > \>\> only a variable it gets the first value:  
> > \>  
> > \>  
> > \> Probably not what you want, but:  
> > \>  
> > \> irb(main):001:0\> def mymethod  
> > \> irb(main):002:1\> return 1, 2  
> > \> irb(main):003:1\> end  
> > \> =\> nil  
> > \> irb(main):004:0\> one = mymethod.first  
> > \> =\> 1  
> > \>  
> > \> Hope that helps.
> > 
> > I think this helps point out that mymethod is not returning  
> > multiple  
> > values, but a single value (an Array object) that contains  
> > multiple values.

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [20 May 2005 15:58 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/2 "2005-05-20T15:58:00Z")

</div>

Hi --

> yep. return 1,2 and return [1,2] work the same. Also when the  
> RHS or LHS of an assign is only single item and the other side  
> is multiple items you can think of that single item being  
> splatted (\*):
> 
> a = 1,2 # \*a = 1,2 # a = [1,2]  
> a,b = [1,2] # a,b = \*[1,2] # a,b = 1,2

Although:

&nbsp;&nbsp;&nbsp;\*a = \*[1,2] # a == [1,2]

🙂

It's hard, I find, to come up with an exact description of what the  
unarr?ay (unary unarray) operator does that fits every case. The  
closest I've come is: \*a = x means: a gets assigned that which, when  
stripped of one level of array-ness, is x. Thus:

&nbsp;&nbsp;&nbsp;\*a = 1,2 # [1,2] stripped of is 1,2 so a is [1,2]  
&nbsp;&nbsp;&nbsp;\*a = \*[1,2] # a stripped of is [1,2] stripped of , so  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# a is [1,2]

&nbsp;&nbsp;&nbsp;def x(\*args); end  
&nbsp;&nbsp;&nbsp;x(1,2,3) # [1,2,3] stripped of is 1,2,3, so args is [1,2,3]  
&nbsp;&nbsp;&nbsp;x([1,2,3]) # [[1,2,3]] stripped of is [1,2,3], so args  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# is [[1,2,3]]

Then there's

&nbsp;&nbsp;&nbsp;a = 1,2 # automatic arraying -- the opposite of \*  
&nbsp;&nbsp;&nbsp;a = \*[1,2] # un-arraying followed by automatic arraying 🙂

or something like that.

David

> **···**
>
> On Sat, 21 May 2005, Eric Mahurin wrote:
> 
> --  
> David A. Black  
> dblack@wobblini.net

---

<div class="post-metadata">

**Author:** ![James\_Britt4](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@James\_Britt4](https://rubytalk.org/u/James_Britt4)\
**Post date:** [20 May 2005 16:30 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/3 "2005-05-20T16:30:13Z")

</div>

Eric Mahurin wrote:

> I've never quite understood why most languages inherently  
> support returning only a single value

Conceptual elegance?

Seems cleaner to say that every expression returns an object, though that the object may be a container for other objects, rather than assert that expressions may return an unknown number of objects

James

---

<div class="post-metadata">

**Author:** ![Ralph\_PJPizza\_Siegle](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Ralph\_PJPizza\_Siegle](https://rubytalk.org/u/Ralph_PJPizza_Siegle)\
**Post date:** [20 May 2005 17:50 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/4 "2005-05-20T17:50:04Z")

</div>

I also think it may be from the original mathematical idea of a "function', which only has 1 output value for a given set of inputs, which 3rd generation programming languages adopted as paradigm. With multiple return values, more in the mindset of a "relation", an n to m mapping

Ralph "PJPizza" Siegler

> **···**
>
> On Sat, May 21, 2005 at 01:30:13AM +0900, James Britt wrote:
> 
> > Eric Mahurin wrote:  
> > \>I've never quite understood why most languages inherently  
> > \>support returning only a single value
> > 
> > Conceptual elegance?
> > 
> > Seems cleaner to say that every expression returns an object, though  
> > that the object may be a container for other objects, rather than assert  
> > that expressions may return an unknown number of objects
> > 
> > James

---

<div class="post-metadata">

**Author:** ![Luca\_Pireddu](https://avatars.discourse-cdn.com/v4/letter/l/8491ac/32.png) [@Luca\_Pireddu](https://rubytalk.org/u/Luca_Pireddu)\
**Post date:** [20 May 2005 18:15 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/5 "2005-05-20T18:15:15Z")

</div>

David A. Black wrote:

> Hi --
> 
> It's hard, I find, to come up with an exact description of what the  
> unarr?ay (unary unarray) operator does that fits every case. The  
> closest I've come is: \*a = x means: a gets assigned that which, when  
> stripped of one level of array-ness, is x. Thus:
> 
> &nbsp;&nbsp;&nbsp;\*a = 1,2 # [1,2] stripped of is 1,2 so a is [1,2]  
> &nbsp;&nbsp;&nbsp;\*a = \*[1,2] # a stripped of is [1,2] stripped of , so  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# a is [1,2]
> 
> &nbsp;&nbsp;&nbsp;def x(\*args); end  
> &nbsp;&nbsp;&nbsp;x(1,2,3) # [1,2,3] stripped of is 1,2,3, so args is [1,2,3]  
> &nbsp;&nbsp;&nbsp;x([1,2,3]) # [[1,2,3]] stripped of is [1,2,3], so args  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# is [[1,2,3]]
> 
> Then there's
> 
> &nbsp;&nbsp;&nbsp;a = 1,2 # automatic arraying -- the opposite of \*  
> &nbsp;&nbsp;&nbsp;a = \*[1,2] # un-arraying followed by automatic arraying 🙂
> 
> or something like that.
> 
> David

Maybe a simpler way to look at it is \*a = x means a = , or simply enclose  
the rhs in an array before assignment.

Luca

> **···**
>
> > On Sat, 21 May 2005, Eric Mahurin wrote:

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [21 May 2005 21:35 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/6 "2005-05-21T21:35:19Z")

</div>

And a simple rule of thumb to 'implement' it is: every time you remove a  
\* on one side of the =, add a to the other side.

\*a = 1,2 --\> a = [1,2]  
\*a = \*[1,2] --\> [a] = [[1,2]] --\> a = [1,2]

etc.

martin

> **···**
>
> David A. Black \<dblack@wobblini.net\> wrote:
> 
> > It's hard, I find, to come up with an exact description of what the  
> > unarr?ay (unary unarray) operator does that fits every case. The  
> > closest I've come is: \*a = x means: a gets assigned that which, when  
> > stripped of one level of array-ness, is x. Thus:

---

<div class="post-metadata">

**Author:** ![Guillaume\_Cottenceau](https://avatars.discourse-cdn.com/v4/letter/g/e19adc/32.png) [@Guillaume\_Cottenceau](https://rubytalk.org/u/Guillaume_Cottenceau)\
**Post date:** [23 May 2005 11:56 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/7 "2005-05-23T11:56:02Z")

</div>

Then you would prefer that a function/method only takes one object as  
parameter, for conceptual elegance?

No, this is all coming from implementation simplification.

> **···**
>
> On 5/20/05, James Britt \<james\_b@neurogami.com\> wrote:
> 
> > Eric Mahurin wrote:  
> > \> I've never quite understood why most languages inherently  
> > \> support returning only a single value
> > 
> > Conceptual elegance?
> > 
> > Seems cleaner to say that every expression returns an object, though  
> > that the object may be a container for other objects, rather than assert  
> > that expressions may return an unknown number of objects
> 
> --  
> Guillaume Cottenceau - [http://zarb.org/~gc/](http://zarb.org/~gc/)

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [20 May 2005 18:20 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/8 "2005-05-20T18:20:15Z")

</div>

Ralph "PJPizza" Siegler wrote:

> > Eric Mahurin wrote:
> > 
> > > I've never quite understood why most languages inherently  
> > > support returning only a single value
> > 
> > Conceptual elegance?
> > 
> > Seems cleaner to say that every expression returns an object, though  
> > that the object may be a container for other objects, rather than  
> > assert that expressions may return an unknown number of objects
> > 
> > James
> 
> I also think it may be from the original mathematical idea of a  
> "function', which only has 1 output value for a given set of inputs,

Mathematical functions are in no way limited to yielding a single output  
value.

> which 3rd generation programming languages adopted as paradigm. With  
> multiple return values, more in the mindset of a "relation", an n to  
> m mapping

That's what a mathematical function is basically. Don't let sin, cos,  
max, min etc. fool you on this one. 🙂

Kind regards

&nbsp;&nbsp;&nbsp;&nbsp;robert

> **···**
>
> > On Sat, May 21, 2005 at 01:30:13AM +0900, James Britt wrote:

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [20 May 2005 19:32 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/9 "2005-05-20T19:32:45Z")

</div>

Hi --

> **···**
>
> On Sat, 21 May 2005, Luca Pireddu wrote:
> 
> > David A. Black wrote:
> > 
> > > Hi --
> > > 
> > > On Sat, 21 May 2005, Eric Mahurin wrote:
> > > 
> > > It's hard, I find, to come up with an exact description of what the  
> > > unarr?ay (unary unarray) operator does that fits every case. The  
> > > closest I've come is: \*a = x means: a gets assigned that which, when  
> > > stripped of one level of array-ness, is x. Thus:
> > > 
> > > &nbsp;&nbsp;&nbsp;\*a = 1,2 # [1,2] stripped of is 1,2 so a is [1,2]  
> > > &nbsp;&nbsp;&nbsp;\*a = \*[1,2] # a stripped of is [1,2] stripped of , so  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# a is [1,2]
> > > 
> > > &nbsp;&nbsp;&nbsp;def x(\*args); end  
> > > &nbsp;&nbsp;&nbsp;x(1,2,3) # [1,2,3] stripped of is 1,2,3, so args is [1,2,3]  
> > > &nbsp;&nbsp;&nbsp;x([1,2,3]) # [[1,2,3]] stripped of is [1,2,3], so args  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# is [[1,2,3]]
> > > 
> > > Then there's
> > > 
> > > &nbsp;&nbsp;&nbsp;a = 1,2 # automatic arraying -- the opposite of \*  
> > > &nbsp;&nbsp;&nbsp;a = \*[1,2] # un-arraying followed by automatic arraying 🙂
> > > 
> > > or something like that.
> > > 
> > > David
> > 
> > Maybe a simpler way to look at it is \*a = x means a = , or simply enclose  
> > the rhs in an array before assignment.
> 
> I'm not sure how that's different from what I was saying above. Or  
> did you mean a simpler way to say it? 🙂
> 
> David
> 
> --  
> David A. Black  
> dblack@wobblini.net

---

<div class="post-metadata">

**Author:** ![Gary\_Wright](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@Gary\_Wright](https://rubytalk.org/u/Gary_Wright)\
**Post date:** [21 May 2005 21:49 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/10 "2005-05-21T21:49:27Z")

</div>

------------------------^  
I think you dropped a '\*':

\*a = \*[1,2] --\> [a] = [\*[1,2]] --\> a = [1,2]

Is there a single good reference page that summarizes the rules for

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;multiple assignment  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;actual to formal argument assignment (for methods/lambdas)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;actual to formal argument assignment (for blocks)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return expression to lhs assignment

I've seen it mentioned that the rules aren't quite identical for  
all these scenarios.

Gary Wright

> **···**
>
> On May 21, 2005, at 5:35 PM, Martin DeMello wrote:
> 
> > And a simple rule of thumb to 'implement' it is: every time you remove a  
> > \* on one side of the =, add a to the other side.
> > 
> > \*a = 1,2 --\> a = [1,2]  
> > \*a = \*[1,2] --\> [a] = [[1,2]] --\> a = [1,2]

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [21 May 2005 22:00 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/11 "2005-05-21T22:00:13Z")

</div>

Hi --

> > It's hard, I find, to come up with an exact description of what the  
> > unarr?ay (unary unarray) operator does that fits every case. The  
> > closest I've come is: \*a = x means: a gets assigned that which, when  
> > stripped of one level of array-ness, is x. Thus:
> 
> And a simple rule of thumb to 'implement' it is: every time you remove a  
> \* on one side of the =, add a to the other side.
> 
> \*a = 1,2 --\> a = [1,2]  
> \*a = \*[1,2] --\> [a] = [[1,2]] --\> a = [1,2]

Yes, though the illegality of [a] = x is what led me to phrase it in  
such a verbose way 🙂

However, using that formula:

&nbsp;&nbsp;&nbsp;a = \*[1,2] --\> [a] = [1,2] --\> a = 1,2

but a = 1,2 is the same as a = [1,2], which means that all of these  
are the same:

&nbsp;&nbsp;&nbsp;a = 1,2  
&nbsp;&nbsp;&nbsp;a = [1,2]  
&nbsp;&nbsp;&nbsp;a = \*[1,2]

which makes sense given the automatic array-wrapping of 1,2 but is  
worth noting since it looks kind of odd.

David

> **···**
>
> On Sun, 22 May 2005, Martin DeMello wrote:
> 
> > David A. Black \<dblack@wobblini.net\> wrote:
> 
> --  
> David A. Black  
> dblack@wobblini.net

---

<div class="post-metadata">

**Author:** ![James\_Britt4](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@James\_Britt4](https://rubytalk.org/u/James_Britt4)\
**Post date:** [23 May 2005 14:05 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/12 "2005-05-23T14:05:44Z")

</div>

Guillaume Cottenceau wrote:

> **···**
>
> > On 5/20/05, James Britt \<james\_b@neurogami.com\> wrote:
> > 
> > > Eric Mahurin wrote:
> > > 
> > > > I've never quite understood why most languages inherently  
> > > > support returning only a single value
> > > 
> > > Conceptual elegance?
> > > 
> > > Seems cleaner to say that every expression returns an object, though  
> > > that the object may be a container for other objects, rather than assert  
> > > that expressions may return an unknown number of objects
> > 
> > Then you would prefer that a function/method only takes one object as  
> > parameter, for conceptual elegance?
> 
> Maybe. A vector.
> 
> Or, um, a list.
> 
> James
> 
> --
> 
> [http://www.ruby-doc.org](http://www.ruby-doc.org) - The Ruby Documentation Site  
> [http://www.rubyxml.com](http://www.rubyxml.com) - News, Articles, and Listings for Ruby & XML  
> [http://www.rubystuff.com](http://www.rubystuff.com) - The Ruby Store for Ruby Stuff  
> [http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys

---

<div class="post-metadata">

**Author:** ![Luca\_Pireddu](https://avatars.discourse-cdn.com/v4/letter/l/8491ac/32.png) [@Luca\_Pireddu](https://rubytalk.org/u/Luca_Pireddu)\
**Post date:** [21 May 2005 06:35 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/13 "2005-05-21T06:35:16Z")

</div>

David A. Black wrote:

> Hi --
> 
> > David A. Black wrote:
> > 
> > > Hi --
> > > 
> > > It's hard, I find, to come up with an exact description of what the  
> > > unarr?ay (unary unarray) operator does that fits every case. The  
> > > closest I've come is: \*a = x means: a gets assigned that which, when  
> > > stripped of one level of array-ness, is x. Thus:
> > > 
> > > &nbsp;&nbsp;&nbsp;\*a = 1,2 # [1,2] stripped of is 1,2 so a is [1,2]  
> > > &nbsp;&nbsp;&nbsp;\*a = \*[1,2] # a stripped of is [1,2] stripped of , so  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# a is [1,2]
> > > 
> > > &nbsp;&nbsp;&nbsp;def x(\*args); end  
> > > &nbsp;&nbsp;&nbsp;x(1,2,3) # [1,2,3] stripped of is 1,2,3, so args is [1,2,3]  
> > > &nbsp;&nbsp;&nbsp;x([1,2,3]) # [[1,2,3]] stripped of is [1,2,3], so args  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# is [[1,2,3]]
> > > 
> > > Then there's
> > > 
> > > &nbsp;&nbsp;&nbsp;a = 1,2 # automatic arraying -- the opposite of \*  
> > > &nbsp;&nbsp;&nbsp;a = \*[1,2] # un-arraying followed by automatic arraying 🙂
> > > 
> > > or something like that.
> > > 
> > > David
> > 
> > Maybe a simpler way to look at it is \*a = x means a = , or simply  
> > enclose the rhs in an array before assignment.
> 
> I'm not sure how that's different from what I was saying above. Or  
> did you mean a simpler way to say it? 🙂
> 
> David

Hello. Yes, I wasn't trying to correct you. Just suggesting a simpler way of  
saying the same thing 🙂

Luca

> **···**
>
> > On Sat, 21 May 2005, Luca Pireddu wrote:
> > 
> > > > On Sat, 21 May 2005, Eric Mahurin wrote:

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [21 May 2005 22:06 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/14 "2005-05-21T22:06:16Z")

</div>

Hi --

> **···**
>
> On Sun, 22 May 2005 gwtmp01@mac.com wrote:
> 
> > On May 21, 2005, at 5:35 PM, Martin DeMello wrote:
> > 
> > > And a simple rule of thumb to 'implement' it is: every time you remove a  
> > > \* on one side of the =, add a to the other side.
> > > 
> > > \*a = 1,2 --\> a = [1,2]  
> > > \*a = \*[1,2] --\> [a] = [[1,2]] --\> a = [1,2]
> > 
> > ------------------------^  
> > I think you dropped a '\*':
> > 
> > \*a = \*[1,2] --\> [a] = [\*[1,2]] --\> a = [1,2]
> 
> I think he meant to. See above: remove a \* and add a . It's  
> happening on both sides here.
> 
> David
> 
> --  
> David A. Black  
> dblack@wobblini.net

---

<div class="post-metadata">

**Author:** ![Michael\_Ulm](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@Michael\_Ulm](https://rubytalk.org/u/Michael_Ulm)\
**Post date:** [23 May 2005 08:23 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/15 "2005-05-23T08:23:38Z")

</div>

Robert Klemme wrote:

> Ralph "PJPizza" Siegler wrote:
> 
> > > Eric Mahurin wrote:
> > > 
> > > > I've never quite understood why most languages inherently  
> > > > support returning only a single value
> > > 
> > > Conceptual elegance?
> > > 
> > > Seems cleaner to say that every expression returns an object, though  
> > > that the object may be a container for other objects, rather than  
> > > assert that expressions may return an unknown number of objects
> > > 
> > > James
> > 
> > I also think it may be from the original mathematical idea of a  
> > "function', which only has 1 output value for a given set of inputs,
> 
> Mathematical functions are in no way limited to yielding a single output  
> value.

\<pedant\_mode\>  
But they are. A (mathematical) function f: M -\> N from a set M to a  
set N is usually defined as a subset of M x N such that for each  
element m in M there exists exactly one element n in N such that  
the pair (m, n) is in the subset; one then writes f(m) = n.  
\</pedant\_mode\>

> > which 3rd generation programming languages adopted as paradigm. With  
> > multiple return values, more in the mindset of a "relation", an n to  
> > m mapping
> 
> That's what a mathematical function is basically. Don't let sin, cos,  
> max, min etc. fool you on this one. 🙂

Maybe you are thinking of vector valued functions, where the return  
value is a vector? In that case, one still has only one return value  
(the vector) which in turn contains other elements. This is very  
similar to returning an array in ruby.

Regards,

Michael

> **···**
>
> > > On Sat, May 21, 2005 at 01:30:13AM +0900, James Britt wrote:
> 
> --  
> Michael Ulm  
> R&D Team  
> ISIS Information Systems Austria  
> tel: +43 2236 27551-219, fax: +43 2236 21081  
> e-mail: michael.ulm@isis-papyrus.com  
> Visit our Website: [www.isis-papyrus.com](http://www.isis-papyrus.com)

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [23 May 2005 16:40 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/16 "2005-05-23T16:40:17Z")

</div>

James Britt wrote:

> Guillaume Cottenceau wrote:
> 
> > > Eric Mahurin wrote:
> > > 
> > > > I've never quite understood why most languages inherently  
> > > > support returning only a single value
> > > 
> > > Conceptual elegance?
> > > 
> > > Seems cleaner to say that every expression returns an object, though  
> > > that the object may be a container for other objects, rather than  
> > > assert that expressions may return an unknown number of objects
> > 
> > Then you would prefer that a function/method only takes one object as  
> > parameter, for conceptual elegance?
> 
> Maybe. A vector.
> 
> Or, um, a list.

Vector implements List...  
😉

&nbsp;&nbsp;&nbsp;&nbsp;Java the Hutt

> **···**
>
> > > On 5/20/05, James Britt \<james\_b@neurogami.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Gary\_Wright](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@Gary\_Wright](https://rubytalk.org/u/Gary_Wright)\
**Post date:** [21 May 2005 23:42 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/17 "2005-05-21T23:42:08Z")

</div>

Yep, my bad. Thanks for the correction to my non-correction.

Gary Wright

> **···**
>
> On May 21, 2005, at 6:06 PM, David A. Black wrote:
> 
> > On Sun, 22 May 2005 gwtmp01@mac.com wrote:
> > 
> > > On May 21, 2005, at 5:35 PM, Martin DeMello wrote:
> > > 
> > > > \*a = \*[1,2] --\> [a] = [[1,2]] --\> a = [1,2]
> > > 
> > > ------------------------^  
> > > I think you dropped a '\*':
> > > 
> > > \*a = \*[1,2] --\> [a] = [\*[1,2]] --\> a = [1,2]
> > 
> > I think he meant to. See above: remove a \* and add a . It's  
> > happening on both sides here.

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [23 May 2005 16:35 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/18 "2005-05-23T16:35:16Z")

</div>

Michael Ulm wrote:

> Robert Klemme wrote:
> 
> > Ralph "PJPizza" Siegler wrote:
> > 
> > > > Eric Mahurin wrote:
> > > > 
> > > > > I've never quite understood why most languages inherently  
> > > > > support returning only a single value
> > > > 
> > > > Conceptual elegance?
> > > > 
> > > > Seems cleaner to say that every expression returns an object,  
> > > > though that the object may be a container for other objects,  
> > > > rather than assert that expressions may return an unknown number  
> > > > of objects
> > > > 
> > > > James
> > > 
> > > I also think it may be from the original mathematical idea of a  
> > > "function', which only has 1 output value for a given set of inputs,
> > 
> > Mathematical functions are in no way limited to yielding a single  
> > output value.
> 
> \<pedant\_mode\>  
> But they are. A (mathematical) function f: M -\> N from a set M to a  
> set N is usually defined as a subset of M x N such that for each  
> element m in M there exists exactly one element n in N such that  
> the pair (m, n) is in the subset; one then writes f(m) = n.  
> \</pedant\_mode\>

So what? M can be A x B x C and N can be D x E - or whatever.

> > > which 3rd generation programming languages adopted as paradigm.  
> > > With multiple return values, more in the mindset of a "relation",  
> > > an n to m mapping
> > 
> > That's what a mathematical function is basically. Don't let sin,  
> > cos, max, min etc. fool you on this one. 🙂
> 
> Maybe you are thinking of vector valued functions, where the return  
> value is a vector? In that case, one still has only one return value  
> (the vector) which in turn contains other elements. This is very  
> similar to returning an array in ruby.

With your reasoning there is also just a single input value for math  
functions. So either functions have a single input and a single output  
value, or multiple at both ends. But claiming that there can be multiple  
input values but only a single output value is at least a bit dishonest  
IMHO.

Kind regards

&nbsp;&nbsp;&nbsp;&nbsp;robert

> **···**
>
> > > > On Sat, May 21, 2005 at 01:30:13AM +0900, James Britt wrote:

---

<div class="post-metadata">

**Author:** ![James\_Britt4](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@James\_Britt4](https://rubytalk.org/u/James_Britt4)\
**Post date:** [23 May 2005 19:02 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/19 "2005-05-23T19:02:48Z")

</div>

Robert Klemme wrote:

> James Britt wrote:  
> ...
> 
> > Maybe. A vector.
> > 
> > Or, um, a list.
> 
> Vector implements List...  
> 😉

Oh, I know.

But references to list processing are more provocative.

🙂

JGB

> **···**
>
> --
> 
> [http://www.ruby-doc.org](http://www.ruby-doc.org) - The Ruby Documentation Site  
> [http://www.rubyxml.com](http://www.rubyxml.com) - News, Articles, and Listings for Ruby & XML  
> [http://www.rubystuff.com](http://www.rubystuff.com) - The Ruby Store for Ruby Stuff  
> [http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys

---

<div class="post-metadata">

**Author:** ![Michael\_Ulm](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@Michael\_Ulm](https://rubytalk.org/u/Michael_Ulm)\
**Post date:** [24 May 2005 06:06 UTC](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537/20 "2005-05-24T06:06:36Z")

</div>

Robert Klemme wrote:

> Michael Ulm wrote:
> 
> > Robert Klemme wrote:
> > 
> > > Ralph "PJPizza" Siegler wrote:
> > > 
> > > > > Eric Mahurin wrote:
> > > > > 
> > > > > > I've never quite understood why most languages inherently  
> > > > > > support returning only a single value
> > > > > 
> > > > > Conceptual elegance?
> > > > > 
> > > > > Seems cleaner to say that every expression returns an object,  
> > > > > though that the object may be a container for other objects,  
> > > > > rather than assert that expressions may return an unknown number  
> > > > > of objects
> > > > > 
> > > > > James
> > > > 
> > > > I also think it may be from the original mathematical idea of a  
> > > > "function', which only has 1 output value for a given set of inputs,
> > > 
> > > Mathematical functions are in no way limited to yielding a single  
> > > output value.
> > 
> > \<pedant\_mode\>  
> > But they are. A (mathematical) function f: M -\> N from a set M to a  
> > set N is usually defined as a subset of M x N such that for each  
> > element m in M there exists exactly one element n in N such that  
> > the pair (m, n) is in the subset; one then writes f(m) = n.  
> > \</pedant\_mode\>
> 
> So what? M can be A x B x C and N can be D x E - or whatever.
> 
> > > > which 3rd generation programming languages adopted as paradigm.  
> > > > With multiple return values, more in the mindset of a "relation",  
> > > > an n to m mapping
> > > 
> > > That's what a mathematical function is basically. Don't let sin,  
> > > cos, max, min etc. fool you on this one. 🙂
> > 
> > Maybe you are thinking of vector valued functions, where the return  
> > value is a vector? In that case, one still has only one return value  
> > (the vector) which in turn contains other elements. This is very  
> > similar to returning an array in ruby.
> 
> With your reasoning there is also just a single input value for math  
> functions. So either functions have a single input and a single output  
> value, or multiple at both ends. But claiming that there can be multiple  
> input values but only a single output value is at least a bit dishonest  
> IMHO.

Indeed, strictly speaking, a mathematical function can only have one  
input value. Mathematically, the notation f(x, y) is just a shorthand  
for f([x, y]). If Kernigan and Richie had paid more attention at  
math class we would have declarations like

(float, float) transform (float, float)

in C, and the world would be a better place for it 🙂

Michael

> **···**
>
> > > > > On Sat, May 21, 2005 at 01:30:13AM +0900, James Britt wrote:
> 
> --  
> Michael Ulm  
> R&D Team  
> ISIS Information Systems Austria  
> tel: +43 2236 27551-219, fax: +43 2236 21081  
> e-mail: michael.ulm@isis-papyrus.com  
> Visit our Website: [www.isis-papyrus.com](http://www.isis-papyrus.com)

[Next page](https://rubytalk.org/t/multiple-return-and-parallel-assignement/18537.md?page=2)
