multi return values

2008-11-21 Thread Andy Colson

(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);


using:
This is Rakudo Perl 6, revision 32970 built on parrot 0.8.1-devel
for i486-linux-thread-multi.

I get:
Method 'lvalue' not found for invocant of class 'PAST;Stmts'
current instr.: 'parrot;PAST;Compiler;as_post' pc 2924
(src/PAST/Compiler.pir:742)
called from Sub 'parrot;PAST;Compiler;post_children' pc 1783
(src/PAST/Compiler.pir:368)
called from Sub 'parrot;PAST;Compiler;as_post' pc 2060
(src/PAST/Compiler.pir:500)
called from Sub 'parrot;PAST;Compiler;post_children' pc 1783
(src/PAST/Compiler.pir:368)
called from Sub 'parrot;PAST;Compiler;pirop' pc 3061
(src/PAST/Compiler.pir:796)
called from Sub 'parrot;PAST;Compiler;post_children' pc 1783
(src/PAST/Compiler.pir:368)
called from Sub 'parrot;PAST;Compiler;as_post' pc 2408
(src/PAST/Compiler.pir:614)
called from Sub 'parrot;PCT;HLLCompiler;compile' pc 434
(src/PCT/HLLCompiler.pir:303)
called from Sub 'parrot;PCT;HLLCompiler;eval' pc 868
(src/PCT/HLLCompiler.pir:502)
called from Sub 'parrot;PCT;HLLCompiler;evalfiles' pc 1233
(src/PCT/HLLCompiler.pir:676)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1412
(src/PCT/HLLCompiler.pir:765)
called from Sub 'parrot;Perl6;Compiler;main' pc 16160 (perl6.pir:168)





Re: multi return values

2008-11-21 Thread Moritz Lenz
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.

(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).

Cheers,
Moritz


-- 
Moritz Lenz
http://perlgeek.de/ |  http://perl-6.de/ | http://sudokugarden.de/


Re: multi return values

2008-11-21 Thread Andy Colson

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 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?


Thanks all,

-Andy




Re: multi return values

2008-11-21 Thread Moritz Lenz
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/


Re: multi return values

2008-11-21 Thread Ryan Richter
On Fri, Nov 21, 2008 at 08:16:21PM +0100, Moritz Lenz wrote:
 Andy Colson wrote:
 (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).

Also this, I think:

  return($a, $b);

-ryan


Re: multi return values

2008-11-21 Thread Carl Mäsak
Ryan (), Moritz (), Andy ():
 (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).

 Also this, I think:

  return($a, $b);

...except that that _is_ a function call.

// Carl


multi return values

2008-11-21 Thread Andy Colson

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);


using:
This is Rakudo Perl 6, revision 32970 built on parrot 0.8.1-devel
for i486-linux-thread-multi.

I get:
Method 'lvalue' not found for invocant of class 'PAST;Stmts'
current instr.: 'parrot;PAST;Compiler;as_post' pc 2924
(src/PAST/Compiler.pir:742)
called from Sub 'parrot;PAST;Compiler;post_children' pc 1783
(src/PAST/Compiler.pir:368)
called from Sub 'parrot;PAST;Compiler;as_post' pc 2060
(src/PAST/Compiler.pir:500)
called from Sub 'parrot;PAST;Compiler;post_children' pc 1783
(src/PAST/Compiler.pir:368)
called from Sub 'parrot;PAST;Compiler;pirop' pc 3061
(src/PAST/Compiler.pir:796)
called from Sub 'parrot;PAST;Compiler;post_children' pc 1783
(src/PAST/Compiler.pir:368)
called from Sub 'parrot;PAST;Compiler;as_post' pc 2408
(src/PAST/Compiler.pir:614)
called from Sub 'parrot;PCT;HLLCompiler;compile' pc 434
(src/PCT/HLLCompiler.pir:303)
called from Sub 'parrot;PCT;HLLCompiler;eval' pc 868
(src/PCT/HLLCompiler.pir:502)
called from Sub 'parrot;PCT;HLLCompiler;evalfiles' pc 1233
(src/PCT/HLLCompiler.pir:676)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1412
(src/PCT/HLLCompiler.pir:765)
called from Sub 'parrot;Perl6;Compiler;main' pc 16160 (perl6.pir:168)