4 ms·
C macros are just a text preprocessor. You could run the C preprocessor on a text file and have the result be Python code. Comments might be a little tricky, bu
by gilch 2y ago
C macros are just a text preprocessor. You could run the C preprocessor on a text file and have the result be Python code. Comments might be a little tricky, but it's doable. Or you can run a text file through a general-purpose one like m4.
For sum types we have enums, and for product types we have tuples (or namedtuples or dataclasses). Sugar could be done with decorators or metaclasses.
For Lisp macros, there's macropy and Hissp.
https://www.gnu.org/software/m4/ https://www.gnu.org/software/m4/
https://threeofwands.com/algebraic-data-types-in-python/ https://threeofwands.com/algebraic-data-types-in-python/
https://github.com/lihaoyi/macropy https://github.com/lihaoyi/macropy
https://github.com/gilch/hissp https://github.com/gilch/hissp
- kazinator 2y agoC preprocessing is token-based. The input is decomposed into preprocessor tokens, sequences of which are then manipulated. There are issues with using stand-alone implementations of C preprocessing like GNU cpp with languages that deviate from C in their token syntax.