Created
April 28, 2018 16:54
-
-
Save zoffixznet/f1f8057c58dc728d1597e877dd277a9f to your computer and use it in GitHub Desktop.
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
sub with-optional($arg?) { # <--- $arg defaults to `Any` type object, if no argument is given | |
say "bob"; # <--- output string `bob`; return True; discard return value | |
$arg; # <--- return value used for `with-optional` sub | |
} | |
with-optional; # no arg given, so `with-optional`'s argument default to `Any`. It's used as return value, which is discarded here | |
with-optional(1); # arg is 1; it's used as return value, so return value is `1`, which is discarded here | |
say with-optional; # no arg = `Any` return value from `with-optional`, which is given as argument to `say, | |
# which outputs it as a string (after some processing). The `say` returns True, which is then discarded | |
say with-optional(1); # 1 as arg = 1 as return value from `with-optional`, which is given as argument to `say, | |
# which outputs it as a string (after some processing). The `say` returns True, which is then discarded | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment