Interpolation vs concatenation

Imagine an alternative timeline where Zig chose interpolation instead of concatenation:

"a\(b)c"
"a" ++ b ++ "c"
.{ a, \(b), c }
.{ a } ++ b ++ .{ c }
foo.@"\(bar)"
@field(foo, bar)
foo(a, \(b), c);
@call(.auto, foo, .{ a } ++ b ++ .{ c });
struct {
	a: i32,
	\(b),
	c: i32,
}
struct {
	a: i32,
	usingnamespace b;
	c: i32,
}
fn make(comptime with_b: bool) type {
	return struct {
		a: i32,
		\(if (with_b) struct { b: i32, } else struct {}),
		c: i32,
	};
}
fn make(comptime with_b: bool) type {
	if (with_b) {
		return struct {
			a: i32,
			b: i32,
			c: i32,
		};
	}
	return struct {
		a: i32,
		c: i32,
	};
}
1 Like

I don’t fully understand your point (there’s not a lot describing your thoughts), but IIUC string interpolation exists in the std.fmt module, like std.fmt.format.

2 Likes