Search code examples
pythonclojuretranslate

Is it possible to translate a clojure syntax into python syntax?


I have been looking around but haven't found an example of this. I'd like to write out a few long/tedious python scripts using Clojure. Just because I happen to enjoy Clojure a bit more and they are not full on programs.

This site makes me think it is possible: http://jkkramer.com/sudoku.html

For example if I have script.clj, I'd like to be able to convert it to script.py - not by hand of course.

Is it possible to do this? If so, what tool/library/script should I use? If its not possible not, why not?

[Edit] I edited this because the wording mistakenly gave the impression I was looking for a detailed lesson on writing my own solution. I was just curious if the tools were out there to answer my question and if not then why not.


Solution

  • Yes. Write a compiler that takes Clojure syntax and outputs valid Python syntax.

    How to do that is well outside of the ability/scope of a StackOverflow answer.

    Also note that if you do this for the general case of compiling any piece of Clojure code to Python you will have implemented quite a bit of Clojure in Python (especially when you implement defmacro and generic methods).