02_std.zig 952 B

123456789101112131415161718192021
  1. //
  2. // Oops! This program is supposed to print a line like our Hello World
  3. // example. But we forgot how to import the Zig Standard Library.
  4. //
  5. // Hint 1: The @import() built-in function returns a value representing
  6. // imported code. We need to give that value a name to use it.
  7. // Hint 2: We use the name "std" in the main function (see below).
  8. // Hint 3: Imports need to be named by declaring them as "const" values.
  9. // Hint 4: Take a look at how the previous exercise did this!
  10. //
  11. @import("std");
  12. pub fn main() void {
  13. std.debug.print("Standard Library.\n", .{});
  14. }
  15. // Going deeper: imports must be declared as "constants" (with the 'const'
  16. // keyword rather than "variables" (with the 'var' keyword) is that they
  17. // can only be used at "compile time" rather than "run time". Zig evaluates
  18. // const values at compile time. Don't worry if none of this makes sense
  19. // yet! See also this answer: https://stackoverflow.com/a/62567550/695615