For long time I have dreamt of invoking Python libraries from scripts written in Scheme. The reason for this is to be able to enjoy the fantastically rich control structures possible in Scheme, yet use familiar libraries to accomplish useful actions, some of which are unavailable in SLIB and other Scheme libraries.
Now at last I am working on realizing this dream. The Scheme implementation being used is version 1.6 of Guile and the Guile extension being developed embeds a Python 2.4 interpreter. In the future, more recent versions of Guile and Python will be used.
The goals of the project are:
- Make it easy to invoke Python libraries from Guile.
- The integration between Python and Guile is to be seamless.
- The architecture of the implementation shall enable optimizations for efficient runtime behavior.
To accomplish those goals, it is necessary to:
- Convert primitive Scheme data types (integers, reals, Booleans, strings, lists) into the corresponding Python data types, and vice versa.
- Be able to invoke functions defined in one language from the other language. This has to be bidirectional in order to support callbacks.
- Be able to pass around pointers to objects (as opaque values) and invoke methods over them.
- Have efficient transfer of control and data between both languages.
- Deal with different garbage collection conventions in both environments.
- Be able to optimize code for a particular pair of language runtime systems.
- Nice to have: support for recursion, especially tail recursion.
- Nice to have: thread-safety.
It is envisioned that the software developed in this project will be part of a larger system, which will allow more scripting languages to interoperate with Guile and with each other.
There is another project – Schemepy – which embeds a Scheme interpreter in Python scripts. This project has different focus and it essentially allows Scheme to be used for those parts of a project, in which its strengths are especially important.