LWN.net Logo

No thanks.

No thanks.

Posted Nov 9, 2012 16:14 UTC (Fri) by apoelstra (subscriber, #75205)
In reply to: No thanks. by HelloWorld
Parent article: Haley: We're doing an ARM64 OpenJDK port!

You know you're on LWN when a language war leads to a comment extolling PostScript over Haskell...


(Log in to post comments)

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:

sub mad { my($a, $b, $c, @rest) = @_; $a*$b+$c, @rest }

So you can use @_ as the forth/postcript stack...

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds