Am I the only one who feels like a curry now?
···
On 5/24/05, Michael Ulm <michael.ulm@isis-papyrus.com> wrote:
Robert Klemme wrote:
> Michael Ulm wrote:
>
>>Robert Klemme wrote:
>>
>>>Ralph "PJPizza" Siegler wrote:
>>>
>>>
>>>>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
>>>>>
>>>>
>>>>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 
--
spooq
Michael Ulm wrote:
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]).
Thank you. It's a relief to have that cleared up.
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 
Dennis Ritchie has a degree in Applied Mathematics from Harvard. Brian
Kernighan was not one of the developers of C, although he co-authored a
famous book with Ritchie. And C functions have been able to return
aggregates for a long time, maybe since the beginning. They're called
structs and unions.
Steve
Steven Jenkins wrote:
Michael Ulm wrote:
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 
Dennis Ritchie has a degree in Applied Mathematics from Harvard. Brian
Kernighan was not one of the developers of C, although he co-authored a
famous book with Ritchie. And C functions have been able to return
aggregates for a long time, maybe since the beginning. They're called
structs and unions.
I'm still waiting for apologies from K & R for having such hard to
spell names...
Of course it is possible to return aggregates in C, it is just not
very convenient. The above type of declaration would not have cost
much in terms of complexity of the language, but it would have made
quite an improvement for code write- and readability.
Michael
···
--
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
Steven Jenkins <steven.jenkins@ieee.org> writes:
Michael Ulm wrote:
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]).
Thank you. It's a relief to have that cleared up.
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 
Dennis Ritchie has a degree in Applied Mathematics from Harvard. Brian
Kernighan was not one of the developers of C, although he co-authored a
famous book with Ritchie. And C functions have been able to return
aggregates for a long time, maybe since the beginning. They're called
structs and unions.
Actually, that is not true. See 6.2 of "The C Programming Language"
(1st ed): The original K&R C could not return compounds, only their
addresses (which is not allowed for "auto" values, not thread-safe for
"static" values and needs memory management for allocated values,
therefore being totally inconvenient.)
This feature must have been added before the 2nd edition (ANSI) was
published, though. My german version already knows about it, and that
was released in 1983. Then, I can't recall any code offhand that
directly returned a structure...
For the tuple issue, there is that "great" (ehem...) paper:
···
Steve
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
Christian Neukirchen wrote:
Steven Jenkins <steven.jenkins@ieee.org> writes:
Dennis Ritchie has a degree in Applied Mathematics from Harvard. Brian
Kernighan was not one of the developers of C, although he co-authored a
famous book with Ritchie. And C functions have been able to return
aggregates for a long time, maybe since the beginning. They're called
structs and unions.
Actually, that is not true. See 6.2 of "The C Programming Language"
(1st ed): The original K&R C could not return compounds, only their
addresses (which is not allowed for "auto" values, not thread-safe for
"static" values and needs memory management for allocated values,
therefore being totally inconvenient.)
Thanks for the clarification. Note that I did say "maybe since the
beginning".
This feature must have been added before the 2nd edition (ANSI) was
published, though. My german version already knows about it, and that
was released in 1983. Then, I can't recall any code offhand that
directly returned a structure...
The High-Order Calculator example in Kernighan and Pike (1984) has a
pop() function that returns a union.
This is not really on-topic any more, so let's let it go. Ritchie
himself has written extensively on the history of C; anyone who's
interested can find it easily.
Steve