C with string interpolation? 🤔 No more confusing format specifiers? No way! 😮
Yeah, Carbon is that great 🎉
const char *name = "Wasym";
const u8 age = 23;
carbon_println("My name is %$, and I am %$ years old", $(name), $(age));
As you saw, we're using these 2 new things:
%$
placeholder: in the same old printf-style, these automatically can infer the type of the variable, and use the appropriate formatting for it. Obviously, you can still use the specific format specifiers if you prefer to do so. 😉$(...)
boxing macro: these are used to wrap around the variables you want to print using the%$
placeholder. As C cannot do any reflection or compile-time type manipulation, we need to do the work at runtime with this handy-dandy macro. 😎
Warning
The $(...) boxing macro only works with lvalues, i.e. variables stored in a way where its address can be retrieved with the &
operator.
Also, logging functions have been reorganized (carbon_log_info
, carbon_log_warn
, carbon_log_error
), which uses our string interpolation mechanism under the hood.
Full Changelog: v0.9-alpha...v0.10-alpha
Note
carbon-0.10-linux-amd64.tgz :: 4f4021abf61bc41a82491b40f4118185a2766dd069f895742f8e0e7e8d2997d9
carbon-0.10-macos-aarch64.tgz :: a8b6043a1d03da75af1b40941945f0cb8233db2c41e6e21816d94767bd12bdf1