suggestions for Lisp syntax to python translator

Discussion of Common Lisp
Post Reply
Gordal
Posts: 5
Joined: Fri Jul 16, 2010 6:10 pm

suggestions for Lisp syntax to python translator

Post by Gordal » Fri Jul 16, 2010 6:44 pm

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!

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: suggestions for Lisp syntax to python translator

Post by ramarren » Fri Jul 16, 2010 9:39 pm

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.

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: suggestions for Lisp syntax to python translator

Post by gugamilare » Sat Jul 17, 2010 6:26 am

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.

Gordal
Posts: 5
Joined: Fri Jul 16, 2010 6:10 pm

Re: suggestions for Lisp syntax to python translator

Post by Gordal » Sat Jul 17, 2010 7:46 am

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.

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: suggestions for Lisp syntax to python translator

Post by nuntius » Sat Jul 17, 2010 10:18 am

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.

calibraxis
Posts: 6
Joined: Mon Jul 05, 2010 12:22 am

Re: suggestions for Lisp syntax to python translator

Post by calibraxis » Sat Jul 17, 2010 5:13 pm

You should ask the clpython-devel list too. Willem Broekema likely has thought about this and could give nuanced advice.

Gordal
Posts: 5
Joined: Fri Jul 16, 2010 6:10 pm

Re: suggestions for Lisp syntax to python translator

Post by Gordal » Mon Jul 19, 2010 12:09 pm

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 :) ...

Warren Wilkinson
Posts: 117
Joined: Tue Aug 10, 2010 11:24 pm
Location: Calgary, Alberta
Contact:

Re: suggestions for Lisp syntax to python translator

Post by Warren Wilkinson » Thu Aug 12, 2010 12:44 am

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.
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.

Gordal
Posts: 5
Joined: Fri Jul 16, 2010 6:10 pm

Re: suggestions for Lisp syntax to python translator

Post by Gordal » Thu Aug 12, 2010 12:45 pm

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

Post Reply