I've got the following trivial script:
#!/usr/bin/env perl6
use v6.c;
sub MAIN($x)
{
say "$x squared is { $x*$x }";
}
This works perfectly fine when calling it with real numbers, but I'd like to pass it complex numbers as well. When I try this as-is, the following happens:
% ./square i
Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏i' (indicated by ⏏)
in sub MAIN at ./square line 7
in block <unit> at ./square line 5
Actually thrown at:
in sub MAIN at ./square line 7
in block <unit> at ./square line 5
When I change my script to
#!/usr/bin/env perl6
use v6.c;
sub MAIN(Complex $x)
{
say "$x squared is { $x*$x }";
}
it stops working completely:
% ./square i
Usage:
square <x>
% ./square 1
Usage:
square <x>
Is there any way to do this in current Perl 6?