Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One way to think about macros is custom syntactic sugar that you can build yourself. So for example, I don't think rust has parameter array (see params/param arrays in c# for an example [1]). So for things like their println that takes variable number of strings to inject into the string where it finds {} it uses the println! and format! macros. Because the parser doesn't support the sugar of a comma separated list and turning that into an array the way c# does (or however other languages handle the same idea), the macro pass of the compiler instead generates the code necessary to make that number of arguments work.

There are likely other uses I've never considered, but that is a simple one.

[1]: https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: