aboutsummaryrefslogtreecommitdiff
path: root/02_std.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-01-03 12:21:11 -0500
committerDave Gauer <dave@ratfactor.com>2021-01-03 12:21:11 -0500
commitd618414c9cd144e3d63f2b12df7b512b98df041c (patch)
tree2b62be68efd03c9454eab640966abf0dc0d21793 /02_std.zig
parent3b5678815f010bd016ca561e4672d2d83271cb2e (diff)
downloadziglings-d618414c9cd144e3d63f2b12df7b512b98df041c.tar.gz
ziglings-d618414c9cd144e3d63f2b12df7b512b98df041c.tar.bz2
ziglings-d618414c9cd144e3d63f2b12df7b512b98df041c.tar.xz
ziglings-d618414c9cd144e3d63f2b12df7b512b98df041c.zip
Added Ex. 2, polished script, added LICENSE
Diffstat (limited to '02_std.zig')
-rw-r--r--02_std.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/02_std.zig b/02_std.zig
new file mode 100644
index 0000000..62ce040
--- /dev/null
+++ b/02_std.zig
@@ -0,0 +1,21 @@
+//
+// Oops! This program is supposed to print a line like our Hello World
+// example. But we forgot how to import the Zig Standard Library.
+//
+// Hint 1: The @import() built-in function returns a value representing
+// imported code. We need to give that value a name to use it.
+// Hint 2: We use the name "std" in the main function (see below).
+// Hint 3: Imports need to be named by declaring them as "const" values.
+// Hint 4: Take a look at how the previous exercise did this!
+//
+@import("std");
+
+pub fn main() void {
+ std.debug.print("Standard Library.\n", .{});
+}
+
+// Going deeper: imports must be declared as "constants" (with the 'const'
+// keyword rather than "variables" (with the 'var' keyword) is that they
+// can only be used at "compile time" rather than "run time". Zig evaluates
+// const values at compile time. Don't worry if none of this makes sense
+// yet! See also this answer: https://stackoverflow.com/a/62567550/695615