#define PASS_VERBOSE if (flag_verbose && first_pass) printf
you just might be able to but only with a completely different tool.A macro processor is not of the language; it is above the language.
#define PASS_VERBOSE if (flag_verbose && first_pass) printf
you just might be able to but only with a completely different tool.A macro processor is not of the language; it is above the language.
Then feel free to use the C preprocessor with Rust, it works just as well. :P Just like it does with Python, and Java, and...
#define whatever(param) \
foo: \
bar \
baz
I made a preprocessor some 18 years ago that could be used with Python.Wayback Machine:
https://web.archive.org/web/20000815202258/http://users.foot...
It's path::to::wherever::PI. That's it. Just like any other item. If you want to use only PI in your code, you'd use 'use', like any other name.
Your second example is something better suited to a macro, it's true.
I _think_ what you're getting at here is that you only want text substitution? I think we will have to agree to disagree if that's true :)
Yes, I do like textual substitution. Guilty. This is a common old school low level paradigm. Still, the underlying language and its compiler exist below to enforce the rules on any atrocities I commit with my macros.
Those who do use and write them heavily are the ones actually involved in the macros 2.0 effort. There are certainly flaws.
The kind of macros Rust implements, on the other hand, are the kind that have to be language-specific, because they deal with the syntax tree of that particular language. They also enable many things that are outright impossible with text substitution, such as hygienic macros.
These two statements are not consistent. Textual substitution is not usable. The pitfalls with it have been well documented for decades, and yet the same problems persist. Why on earth would you want to perpetuate the list of problems caused by such a facility?
Syntactic macros are absolutely superior to textual substitution. You can take issue with Rust's currently limited support for macros, but to propose textual substitution as a viable and more usable alternative is simply absurd.