Hacker News new | ask | show | jobs
by gilch 568 days 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://threeofwands.com/algebraic-data-types-in-python/

https://github.com/lihaoyi/macropy

https://github.com/gilch/hissp

1 comments

C 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.