From: "kid51" at 192.168.1.3
Summary: Rakudo rock-scissors-paper example
Running this from Using Perl6 PDF:
use v6;
enum Symbol ;
multi wins(Scissors $, Paper $) { +1 }
multi wins(Paper $, Rock $) { +1 }
multi wins(Rock $, Scissors $) { +1 }
multi wins(::T $, T $) { 0 } # type capture
multi wins( $, $) { -1 }
sub play ($a,$b) {
given wins($a,$b) {
when +1 { say "Player One wins" }
when 0 { say "Draw" }
when -1 { say "Player Two wins" }
}
}
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Use of uninitialized value in numeric context
Player One wins
Player One wins
Player One wins
... no line numbers for uninitialized values; wrong results; did I type the example wrong?
Results are fine for me with Rakudo 82ebb545e88c8b754b35f31b59002efdd4d2d7fd. I still get the "Use of uninitialized value in numeric context" messages, though...
This content is stored as http://nopaste.snit.ch/23640.
From: "kid51" at 192.168.1.3 Summary: Rakudo rock-scissors-paper example
Running this from Using Perl6 PDF:
use v6;
enum Symbol;
multi wins(Scissors $, Paper $) { +1 } multi wins(Paper $, Rock $) { +1 } multi wins(Rock $, Scissors $) { +1 } multi wins(::T $, T $) { 0 } # type capture multi wins( $, $) { -1 }
sub play ($a,$b) { given wins($a,$b) { when +1 { say "Player One wins" } when 0 { say "Draw" } when -1 { say "Player Two wins" } } }
play(Scissors, Paper); play(Paper, Paper); play(Rock, Paper);
... gives this output:
Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Use of uninitialized value in numeric context Player One wins Player One wins Player One wins
... no line numbers for uninitialized values; wrong results; did I type the example wrong?