2 ms·
A macro is a function that takes in parsed code and returns transformed code. The nice thing about macros is that they run during the parsing of the code, so t
by eigenspace 11mo ago
A macro is a function that takes in parsed code and returns transformed code.
The nice thing about macros is that they run during the parsing of the code, so they have no runtime cost associated with them.
Basically, you can think of it as a (limited) way for users or packages to add new keywords to a language without having to change the whole language implementation for everyone.
Many recent new keywords that were added to Python could have been implemented as macros, which means that they could have just lived in packages rather than needing to be upstreamed into the base language implementation from day 1.