Is there any tool to translate Lisp code to Python?

Because I want to use Lisp syntax and Python libraries.

Perhaps some tools like Parenscript, but generate Python code instead of Javascript.

+6
source share
2 answers

I experimented a bit with the Lisp compiler targeting Python bytecode .

Here you can see a small video here .

This is just a proof-of-concept toy, but it is an IMO a viable way, and the end result could be called and called from python freely (and it would be compatible with any python extension library). However, all this preserves the power of macros (metaprogramming is probably the area that Python is further from lisp).

Targeting Python source code instead is rather unpleasant, because there are explicit syntax restrictions that make Lisp compilation difficult (for example, assignment is not an expression, statement statement is not allowed in iamba, captured variables are read-only in Python 2.x).

However, VM runtime does not have these limitations, and Python bytecode is good enough.

Currently, my toy can target Python 2.x, Python 3.x and even works with PyPy (so you get a JIT compiler too).

Of course, striving to become a full-fledged implementation of Common Lisp would be an IMO error from a technical point of view, but a Lisp dialect based on Python execution types and compatible with the Python object system could become a sensible tool with practical applications.

+7
source

I believe Hy is what you are looking for. From the textbook:

Hy is converted to its own pythons syntax tree, so you'll soon start to find that all the familiar power of python is at hand.

However, note that Hy is not a common Lisp, so you cannot cut and paste.

+3
source

Source: https://habr.com/ru/post/952863/


All Articles