Raku / book

Using Raku – an unfinished book about Raku
https://perl6book.com/
284 stars 49 forks source link

Using Perl6: Section 5.3: rock-scissors-paper example not working #30

Closed jkeenan closed 13 years ago

jkeenan commented 13 years ago

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?

colomon commented 13 years ago

Results are fine for me with Rakudo 82ebb545e88c8b754b35f31b59002efdd4d2d7fd. I still get the "Use of uninitialized value in numeric context" messages, though...