aboutsummaryrefslogtreecommitdiff
path: root/18_functions.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-02-07 11:06:51 -0500
committerDave Gauer <dave@ratfactor.com>2021-02-07 11:06:51 -0500
commitadf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a (patch)
treea25511c3bb20069f1d6123366573c82c5745338b /18_functions.zig
parent507355ec3b1066c707e19816b86ac1fb56fc0385 (diff)
downloadziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.gz
ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.bz2
ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.xz
ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.zip
Consistent instructions and examples
I started off with "hints" that required the poor student to piece together the information from incomplete bits. A complete example is like a picture that is worth 1000 words and far clearer.
Diffstat (limited to '18_functions.zig')
-rw-r--r--18_functions.zig23
1 files changed, 17 insertions, 6 deletions
diff --git a/18_functions.zig b/18_functions.zig
index ad97585..bda90cd 100644
--- a/18_functions.zig
+++ b/18_functions.zig
@@ -1,5 +1,18 @@
//
-// Functions! FUNctions! FUN!
+// Functions! We've already seen a lot of one called "main()". Now let's try
+// writing one of our own:
+//
+// fn foo(n: u8) u8 {
+// return n+1;
+// }
+//
+// The foo() function above takes a number "n" and returns a number that is
+// larger by one.
+//
+// If your function doesn't take any parameters and doesn't return anything,
+// it would be defined like main():
+//
+// fn foo() void { }
//
const std = @import("std");
@@ -11,12 +24,10 @@ pub fn main() void {
}
//
-// We're just missing a couple things here. One thing we're NOT missing is the
-// keyword "pub", which is not needed here. Can you guess why?
+// Please define the deepThought() function below.
//
-// Functions need to specify the type of value they return. The main() function
-// above has a special return type "void", which means it returns nothing. This
-// function returns something. What might that be?
+// We're just missing a couple things. One thing we're NOT missing is the
+// keyword "pub", which is not needed here. Can you guess why?
//
??? deepThought() ??? {
return 42; // Number courtesy Douglas Adams