Dave Gauer 4 лет назад
Родитель
Сommit
4a379159a3
4 измененных файлов с 34 добавлено и 1 удалено
  1. 1 1
      README.md
  2. 4 0
      build.zig
  3. 25 0
      exercises/083_anonymous_lists.zig
  4. 4 0
      patches/patches/083_anonymous_lists.patch

+ 1 - 1
README.md

@@ -148,7 +148,7 @@ Core Language
 * [x] Comptime
 * [x] Sentinel termination
 * [x] Quoted identifiers @""
-* [ ] Anonymous structs
+* [x] Anonymous structs/tuples/lists
 * [ ] Suspend / Resume
 * [ ] Async / Await
 * [ ] Nosuspend

+ 4 - 0
build.zig

@@ -409,6 +409,10 @@ const exercises = [_]Exercise{
         .output = "\"0\"(bool):true \"1\"(bool):false \"2\"(i32):42 \"3\"(f32):3.14159202e+00",
         .hint = "This one is a challenge! But you have everything you need."
     },
+    .{
+        .main_file = "083_anonymous_lists.zig",
+        .output = "I say hello!",
+    },
 };
 
 /// Check the zig version to make sure it can compile the examples properly.

+ 25 - 0
exercises/083_anonymous_lists.zig

@@ -0,0 +1,25 @@
+//
+// Anonymous struct literal syntax can also be used to compose an
+// "anonymous list" with an array type destination:
+//
+//     const foo: [3]u32 = .{10, 20, 30};
+//
+// Otherwise it's a "tuple":
+//
+//     const bar = .{10, 20, 30};
+//
+// The only difference is the destination type.
+//
+const print = @import("std").debug.print;
+
+pub fn main() void {
+    // Please make 'hello' a string-like array of u8 WITHOUT
+    // changing the value literal.
+    //
+    // Don't change this part:
+    //
+    //     = .{'h', 'e', 'l', 'l', 'o'};
+    //
+    const hello = .{'h', 'e', 'l', 'l', 'o'};
+    print("I say {s}!\n", .{hello});
+}

+ 4 - 0
patches/patches/083_anonymous_lists.patch

@@ -0,0 +1,4 @@
+23c23
+<     const hello = .{'h', 'e', 'l', 'l', 'o'};
+---
+>     const hello: [5]u8 = .{'h', 'e', 'l', 'l', 'o'};