summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorven <vendethiel@hotmail.fr>2017-05-25 15:06:13 +0200
committerGitHub <noreply@github.com>2017-05-25 15:06:13 +0200
commit66c4b1c01a26fed2b55ff50b4aba8b2c5eb9061c (patch)
treec8109cf87f1e86612b07168718121a9ef5b0aa05
parentae9762fd13dc75113a8d64091181477510825819 (diff)
fix #1155
-rw-r--r--perl6.html.markdown33
1 files changed, 29 insertions, 4 deletions
diff --git a/perl6.html.markdown b/perl6.html.markdown
index ee94f5bf..d0ccdc9a 100644
--- a/perl6.html.markdown
+++ b/perl6.html.markdown
@@ -118,13 +118,38 @@ say %hash<key2>; # If it's a string, you can actually use <>
# created with the `sub` keyword.
sub say-hello { say "Hello, world" }
-sub say-hello-to(Str $name) { # You can provide the type of an argument
- # and it'll be checked at compile-time.
-
+# You can provide (typed) arguments.
+# If specified, the type will be checked at compile-time if possible,
+# otherwise at runtime.
+sub say-hello-to(Str $name) {
say "Hello, $name !";
}
-## It can also have optional arguments:
+# A sub returns the last value of the block.
+sub return-value {
+ 5;
+}
+say return-value; # prints 5
+sub return-empty {
+}
+say return-empty; # prints Nil
+
+# Some control flow structures produce a value, like if:
+sub return-if {
+ if True {
+ "Truthy";
+ }
+}
+say return-if; # prints Truthy
+
+# Some don't, like for:
+sub return-for {
+ for 1, 2, 3 { }
+}
+say return-for; # prints Nil
+
+
+## A sub can have optional arguments:
sub with-optional($arg?) { # the "?" marks the argument optional
say "I might return `(Any)` (Perl's 'null'-like value) if I don't have
an argument passed, or I'll return my argument";