aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--build.zig5
-rw-r--r--exercises/079_quoted_identifiers.zig30
-rw-r--r--patches/patches/079_quoted_identifiers.patch12
4 files changed, 48 insertions, 0 deletions
diff --git a/README.md b/README.md
index 41083f1..021218c 100644
--- a/README.md
+++ b/README.md
@@ -147,6 +147,7 @@ Core Language
* [x] Inline loops
* [x] Comptime
* [x] Sentinel termination
+* [x] Quoted identifiers @""
* [ ] Anonymous structs
* [ ] Suspend / Resume
* [ ] Async / Await
diff --git a/build.zig b/build.zig
index 391da47..c66f613 100644
--- a/build.zig
+++ b/build.zig
@@ -391,6 +391,11 @@ const exercises = [_]Exercise{
.main_file = "078_sentinels3.zig",
.output = "Weird Data!",
},
+ .{
+ .main_file = "079_quoted_identifiers.zig",
+ .output = "Sweet freedom: 55, false.",
+ .hint = "Help us, Zig Programmer, you're our only hope!",
+ },
};
/// Check the zig version to make sure it can compile the examples properly.
diff --git a/exercises/079_quoted_identifiers.zig b/exercises/079_quoted_identifiers.zig
new file mode 100644
index 0000000..a529b60
--- /dev/null
+++ b/exercises/079_quoted_identifiers.zig
@@ -0,0 +1,30 @@
+//
+// Sometimes you need to create an identifier that will not, for
+// whatever reason, play by the naming rules:
+//
+// const 55_cows: i32 = 55; // ILLEGAL: starts with a number
+// const isn't true: bool = false; // ILLEGAL: what even?!
+//
+// If you try to create either of these under normal
+// circumstances, a special Program Identifier Syntax Security
+// Team (PISST) will come to your house and take you away.
+//
+// Thankfully, Zig has a way to sneak these wacky identifiers
+// past the authorities: the @"" identifier quoting syntax.
+//
+// @"foo"
+//
+// Please help us safely smuggle these fugitive identifiers into
+// our program:
+//
+const print = @import("std").debug.print;
+
+pub fn main() void {
+ const 55_cows: i32 = 55;
+ const isn't true: bool = false;
+
+ print("Sweet freedom: {}, {}.\n", .{
+ 55_cows,
+ isn't true,
+ });
+}
diff --git a/patches/patches/079_quoted_identifiers.patch b/patches/patches/079_quoted_identifiers.patch
new file mode 100644
index 0000000..c7bcea8
--- /dev/null
+++ b/patches/patches/079_quoted_identifiers.patch
@@ -0,0 +1,12 @@
+23,24c23,24
+< const 55_cows: i32 = 55;
+< const isn't true: bool = false;
+---
+> const @"55_cows": i32 = 55;
+> const @"isn't true": bool = false;
+27,28c27,28
+< 55_cows,
+< isn't true,
+---
+> @"55_cows",
+> @"isn't true",