Your analysis of Joel's article seems quite shallow, I think that you are prejudiced against him and you should reread his article, his points aren't bad.
Also why do you consider returning a tuple different from returning multiple values?
The only thing that matter is allowing the programmer to have a readable way to access multiple return values ( y,z = f(x) ), whether these return values are in a tuple or not is not so important, thought I would argue that the tuple is better as it also allow f(g(x)) so it's better (provided it still allow the simple access to the multiples values).
Posted Nov 9, 2012 15:49 UTC (Fri) by HelloWorld (guest, #56129)
[Link]
Your analysis of Joel's article seems quite shallow,
Feel free to write a rebuttal. Until then, I'll consider my points valid.
Also why do you consider returning a tuple different from returning multiple values?
I consider them different because they are different (duh). Let's say you have a function that duplicates its argument. In Haskell using a tuple, that's
dup x = (x,x)
Now assume a multiply-add function:
mad a b c = a*b+c
How can you combine these to write a function that returns x*x+x? In a language like Haskell you can't easily do it with for example composition, you have to do something like
foo x = mad x x x
otoh, PostScript actually allows you to return multiple values, and there it's trivial:
/mad { mul add } def
/foo { dup dup mad } def
(dup is a builtin in PostScript)
No thanks.
Posted Nov 9, 2012 16:14 UTC (Fri) by apoelstra (subscriber, #75205)
[Link]
You know you're on LWN when a language war leads to a comment extolling PostScript over Haskell...
No thanks.
Posted Nov 9, 2012 21:33 UTC (Fri) by HelloWorld (guest, #56129)
[Link]
It was the most well-known language I could think of that actually supports returning multiple values. Lua supposedly allows it too, but it's limited.
Simple things work
function dup(x) return x, x end
function add(x,y) return x, y end
print(add(dup(3))) -- prints 6
but more somplex examples, such as
function dup(x) return x, x end
function mad(x,y,z) return x*y+z end
print(mad(dup(dup(3))))
don't. I'm not sure it can work in a non-stack-based language.
No thanks.
Posted Nov 10, 2012 0:22 UTC (Sat) by hummassa (subscriber, #307)
[Link]
works perfectly in perl:
sub dup { $_[0], @_ }
sub mad { $_[0]*$_[1]+$_[2] }
say mad dup dup 3
No thanks.
Posted Nov 10, 2012 14:09 UTC (Sat) by HelloWorld (guest, #56129)
[Link]
This works because your version of dup returns excess arguments unmodified. Most perl functions don't do that, so it's not quite the same thing.
No thanks.
Posted Nov 11, 2012 0:44 UTC (Sun) by hummassa (subscriber, #307)
[Link]
It does that because I modelled it after the postcript/forth example. In perl, is actually quite easy to adopt this style of programming:
Basically, the `const' adds a fourth (ignored) parameter to `mad' and then we uncurry that function to get it to take a tuple of tuples and then `dup . dup' the input to make `((x, x), (x, x))'. Granted, this looks nasty, but is also something that lamdabot might have been able to generate when asking for how to rewrite the obvious implementation in a point-free way.