Andy Colson wrote:
> Moritz Lenz wrote:
>> Andy Colson wrote:
>>> (Sorry if this dbl-posts, sent it from the wrong account the first time)
>>>
>>> Hi all, what's wrong with this code:
>>>
>>> use v6;
>>>
>>> sub multireturn($x, $y)
>>> {
>>> my $a = $x * 2;
>>> my $b = $y * 2;
>>> return($a, $b);
>>> }
>>>
>>> my($a, $b) = multireturn(2, 3);
>>
>> There's (nearly) nothing wrong with your code, only with the compiler ;-)
>>
>> Rakudo doesn't support list assignment yet (that's where the error
>> message comes from), and doesn't support returning values either.
>>
>> A workaround for now is to use arrays instead.
>
> You mean like:
>
> my @list = multireturn(2, 3);
That, and make multireturn return an array, not a list.
> That still doesn't work. But its not a big deal... I was just playing
> around trying to learn the language.
>
>>
>> (The thing that's still wrong with your code is that you need a
>> whitespace after the 'my', otherwise my(...) should be parsed as a
>> function call).
>
> OH! Good call, I'd forgotten about that. That's going to take some
> getting used to. I assume it'll error out and say "method my not found?"
s/method/sub/, but apart from that: yes.
--
Moritz Lenz
http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/