From adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a Mon Sep 17 00:00:00 2001 From: Dave Gauer Date: Sun, 7 Feb 2021 11:06:51 -0500 Subject: 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. --- 18_functions.zig | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to '18_functions.zig') 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 -- cgit v1.2.3-ZIG