Forked from dogbert17/gist:dcf078ff80c7b868dfdce95632b4ad63
Last active
July 16, 2016 15:23
-
-
Save gfldex/ecde10b59aab332941a245dc4e74ddf0 to your computer and use it in GitHub Desktop.
Taken from https://docs.perl6.org/language/functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to be wrapped: | |
sub square-root($x) { $x.sqrt } | |
&square-root.wrap(sub ($num) { | |
nextsame if $num >= 0; | |
1i * callwith(abs($num)); | |
}); | |
say square-root(4); # 2 | |
say square-root(-4); # 0+2i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment