Page 1 of 1

suggestions for Lisp syntax to python translator

Posted: Fri Jul 16, 2010 6:44 pm
by Gordal
Im embarking on making a lisp syntax to python translator so as to enjoy lisp macros and reader macros and such in python while gaining access to all the libraries and the cutting edge implementations (like pypy, stackless python and microthreads!) :mrgreen:

To start i was wondering if anyone here is aware of any similar lisp projects of which i can take advantage of. And if there were any issues anyone could think of which would be a show stopper.

Both are typeless, the only 'hard' thing i can think of is that python doesn't allow arbitrarily nested code (for example, while statements in function parameters). However, i *believe* that all arbitrarily nested code can be converted to what python expects.

Another difficulty would be mapping python errors to the location which the errors correspond to in the lisp code (since we have to un nest arbitrary lisp code)

Any suggestions? Thanks!

Re: suggestions for Lisp syntax to python translator

Posted: Fri Jul 16, 2010 9:39 pm
by ramarren
You should first decide whether you want to write a (Common) Lisp to Python compiler, or Lispy syntax to Python. The former is hard for any complete subset of CL, since there is a significant impedance mismatch between high level features. Dropping CLOS would make things easier, probably. Also, neither Python or Common Lisp are "typeless". Assembler and Forth are typeless, Python and CL are dynamically and strongly typed.

The latter is much easier, and has been done for javascript, although I believe they have been expanding with compiler-like features for some time. You might want to look there for inspiration.

Re: suggestions for Lisp syntax to python translator

Posted: Sat Jul 17, 2010 6:26 am
by gugamilare
You can change the approach to your problem if you want to be able to use Python's libraries. There are ClPython (which implements Python in Common Lisp) and Python On Lisp (which lets you communicate with a Python implementation). Both approaches would be less error-prone than implementing your own translator, as Common Lisp is a very big and complex language.

Creating an FFI binding on your own or updating Python On Lisp would also look nice and should not be too hard.

Re: suggestions for Lisp syntax to python translator

Posted: Sat Jul 17, 2010 7:46 am
by Gordal
Im definitely just planning a lisp syntax for python, augmented with macros and reader macros! Nothing too ambitious. :D

edit: ok, so ive been trying it out, not too hard actually, i just wanted to make sure there wasn't any past effort out there that i could utilize.

Re: suggestions for Lisp syntax to python translator

Posted: Sat Jul 17, 2010 10:18 am
by nuntius
IMO, the first step would be to write a system that translates parentheses into indentation. Shouldn't be too hard. Then for each Python syntax, you will need to pick a matching s-expression. You can then implement these as functions which print python code.

Re: suggestions for Lisp syntax to python translator

Posted: Sat Jul 17, 2010 5:13 pm
by calibraxis
You should ask the clpython-devel list too. Willem Broekema likely has thought about this and could give nuanced advice.

Re: suggestions for Lisp syntax to python translator

Posted: Mon Jul 19, 2010 12:09 pm
by Gordal
Even though im still trying this approach (which i like best), i noticed that pypy (a python compiler) has a common lisp backend. have to take a look at that soon :) ...

Re: suggestions for Lisp syntax to python translator

Posted: Thu Aug 12, 2010 12:44 am
by Warren Wilkinson
I suggest you ensure that the Python libraries are worth the trouble of programming through a straw. Snipes aside, Paren script (http://www.cliki.net/Parenscript) is a lisp library that transforms s-expressions into javascript. You might find applicable techniques in that package.

Re: suggestions for Lisp syntax to python translator

Posted: Thu Aug 12, 2010 12:45 pm
by Gordal
I would have to say, after programming during the summer in python, that yes, python libraries are definitely worth it! And since ive posted this i have a sort of functioning prototype lisp syntax to python translator that takes care of arbitrary nesting expansion. but i am looking into doing it properly using continuation intermediate form (well it looks cool) maybe something like http://lambda-the-ultimate.org/node/2406

Python is basically lisp except without the syntax and thus without macros. And of course everything is an object which is actually quite nice you can customize everything (a function is an object, but you dont feel like it is, so you can program functionally all you want). And its getting a lot faster with JIT compilers. So yep python with lisp syntax is best. :D