Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created March 17, 2009 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j1n3l0/80450 to your computer and use it in GitHub Desktop.
Save j1n3l0/80450 to your computer and use it in GitHub Desktop.
Casting, Signatures & Return Types in rakudo
multi sub to_num(Str $number) returns Num { +$number }
my $s = "10";
my $i = to_num($s);
say 'before: ' ~ $s.WHAT; # before: Str
say 'after : ' ~ $i.WHAT; # after : Num
=begin pod
=item Casting
Q: Is it currently possible to convert a Str to a Num e.g. the return value of prompt()?
A: Yes -- $number = +$string
=item Return types
Q: Should a sub/method/function complain if the return value does not match the specified type?
A: Yes -- Not implemented yet
=item Signatures
Q: Is the return type part of the signature and if not should it be?
A: Yes -- multi sub to_num(Str $s --> Num) { +$s }
=end pod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment