Question

Because I want to use Lisp's syntax and Python's libraries.

Maybe some tools like Parenscript but generates Python code instead of Javascript.

Was it helpful?

Solution

I've been experimenting a bit with a Lisp compiler targeting Python bytecode.

You can see a small video here.

It's just a proof-of-concept toy but it's IMO a viable path and the end result would be able to call and be called from python freely (and it would be compatible with any python extension library). All this keeping however the power of macros (metaprogramming is probably the area in which Python is farthest from lisp).

Targeting Python source code instead is quite more annoying to do because there are explicit syntax limitations that make compiling Lisp difficult (e.g. assignment is not an expression, no statement is permitted in lambda, captured variables are read-only in Python 2.x).

The VM runtime however doesn't have these limitations and Python bytecode is reasonably nice.

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

Of course aiming at becoming a full compliant Common Lisp implementation would be IMO nonsense from a technical point of view, but a lisp dialect based on Python runtime types and compatible with Python object system could instead be a reasonable tool with practical applications.

OTHER TIPS

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

Hy converts to python’s own abstract syntax tree, so you’ll soon start to find that all the familiar power of python is at your fingertips.

However note that Hy isn't Common Lisp, so you can't cut and paste.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top