j1n3l0 has asked for the wisdom of the Perl Monks concerning the following question:
Questions: Casting Is it currently possible to convert a type Str "10" to a type Num 10 e.g. the return value of the builtin prompt()? Return types Should a sub/method/function complain if the return value does not match the specified type, in this case Num? Signatures Is the return type part of the signature and if not should it be? Thanks =)multi sub to_num(Str $number where { $_ ~~ /^ \d+ $/ }) returns Num { ++$number } my $s = "10"; my $i = to_num($s); say 'before: ' ~ $s.WHAT; # before: Str say 'after : ' ~ $i.WHAT; # after : Num
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: casting, signatures and return types in perl 6 (rakudo)
by moritz (Cardinal) on Mar 17, 2009 at 14:42 UTC | |
by j1n3l0 (Friar) on Mar 17, 2009 at 14:54 UTC |