Polyglot
2025-09-08
While nimpylib(repo) is handy to write Python code in Nim,
what if writing polyglot code, which is runnable in both Nim and Python?
An example (NPython’s test_decimalAndSpace.nim) using such polyglot
How to
We simply write two parts:
- run in both languages (thanks to their similar syntax)
- snippets run in only one, ignored by another
Many parts of syntax of they two are similar, so we don’t discuss such here
and what’s more important is that how to make some code ignored by specified one language