So I had a crazy little idea. I've played the odd bit of roleplaying in my
time and wanted to created a 'd' operator.

Quite simple really.

sub infix:<d> ( Int $num, Int $size ) { [+] (1..$size).roll($num) };

sub prefix:<d> ( Int $size ) { 1 d $size }

Gives us 3 d 6 to roll 3 six sided dice or a prefix d 10 for a single 10
sided dice.

Except... I'd really like to write 3d6 or d10 but the parser barfs.

Am I going to just have to live with that? Or did I miss something obvious?

Obviously it's possible to have operators that ignore whitespace (1+1 works
just fine) but is it possibly for user defined ones?

Possibly more serious ones.

Simon

Reply via email to