aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-05-09 19:53:14 -0400
committerDave Gauer <dave@ratfactor.com>2021-05-09 19:53:14 -0400
commit4ac081558cc7105dfd9ad9faed5998691a21460a (patch)
tree050fdf1e545c90c2556e776449629ecf83a9a757
parent5ff9d692314e9d319e85780d9281878ea5fc6107 (diff)
downloadziglings-4ac081558cc7105dfd9ad9faed5998691a21460a.tar.gz
ziglings-4ac081558cc7105dfd9ad9faed5998691a21460a.tar.bz2
ziglings-4ac081558cc7105dfd9ad9faed5998691a21460a.tar.xz
ziglings-4ac081558cc7105dfd9ad9faed5998691a21460a.zip
add ex083 anon lists
-rw-r--r--README.md2
-rw-r--r--build.zig4
-rw-r--r--exercises/083_anonymous_lists.zig25
-rw-r--r--patches/patches/083_anonymous_lists.patch4
4 files changed, 34 insertions, 1 deletions
diff --git a/README.md b/README.md
index 021218c..7a44cf0 100644
--- a/README.md
+++ b/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
diff --git a/build.zig b/build.zig
index 90d8a0b..1269a0e 100644
--- a/build.zig
+++ b/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.
diff --git a/exercises/083_anonymous_lists.zig b/exercises/083_anonymous_lists.zig
new file mode 100644
index 0000000..838d40e
--- /dev/null
+++ b/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});
+}
diff --git a/patches/patches/083_anonymous_lists.patch b/patches/patches/083_anonymous_lists.patch
new file mode 100644
index 0000000..b981909
--- /dev/null
+++ b/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'};