Sunday, March 18, 2012

Clojure with Python syntax

This post is of the brainstorming variety. It is a project that I might undertake in the future, when I have time.

Many programmers (not me, but apparently a large number) find Python to be a readable language, and Lisp to not be readable. You give up macros when using Python, but maybe that's not a big deal to many developers. Maybe if you're running a company with a lot of turnover, macros aren't a big deal. Or maybe you just don't understand or don't care about macros. I love them but they can be hard to get right.

So what if there was a language with Python syntax, complete with whitespace rules, that compiled to Clojure? My google-fu did not find any such projects. Clojure is a really good language even without macros. The code generated by the new language would be trivially interoperable with any other Clojure code.

It would have to make available everything that is in Clojure. I have no idea how much work it would be to:
  • Parse a Pythonesque language
  • Provide access to everything in Clojure core
  • Keep up with all new releases of Clojure
  • Write documentation
  • Produce Clojure code that is easy to read and modify (should not be difficult)
I don't know anything about designing a language, I don't know a lot about Python, and I don't have a solid understanding of many parts of Clojure. I wouldn't actually be implementing anything, and I would be borrowing the syntax of an existing language, but that doesn't mean it would be something that could be done in a weekend. I'd only call it a language because it technically would be a different language.


The goals would be:
  • Eliminate the Lisp syntax barrier to getting programmers to try Clojure.
  • Make Clojure acceptable to universities that want to avoid Lisp syntax.
  • Provide a stepping stone so that programmers can learn Clojure concepts, then when they want more control over their language, they can start writing Clojure without giving up any of their existing code.
Any constructive feedback, positive or negative, is welcome. I'd especially appreciate links to a project that already does what I'm proposing. And suggestions for the best way to proceed. I want to be clear that this is only something I've been thinking about the last couple months as a way to bring Clojure to the world, it would not compete with Clojure, and I haven't done any work on it.

13 comments:

Anonymous said...

Why don't you just write a 'clojure' library for python. Problem solved. Syntax for lisp? Then it's no longer a lisp. I always thought that's obvious. When in doubt, go visit the dylan folks.

Anonymous said...

Check out Julia (http://julialang.org). It's pretty clearly a LISP derivative, though it's not as mature as clojure yet. The syntax is so close to Python that I keep typing ':' after if statements. And it has macros every bit as powerful as clojures.

Simon Hawkin said...

A Python DSL in Clojure? Too difficult without reader macros, but who knows.

coco said...

sorry man but it hasn't any sense...the power about clojure and lisp is than this is homoiconic..python don't, you can't write full powered lisp with python so..if you don't like the lisp syntax maybe would be a better idea begin use haskell or f#, both has similar syntax to python, actually, f# has the "in-famous" indentation, but in this case it's not obligatory..

when I begin learn clojure many things was weird to me..but basically all the weird things are related to the great consistence from lisp and clojure, you don't need create a new syntax when you use clojure because its syntax let you write everything...so..

I repeat you, if you're interested in functional languages but don't like lisp syntax, you has ocaml haskell or f#... but please..don't try mix milk with vodka...if you are really interested in lisp then learn lisp syntax, which by the way, it's the most powerfull syntax ever...

Andrew said...

It is worth bearing in mind that, originally, lisp wasn't designed to be written in s-expressions either.

McCarthy proposed writing in m-expressions, which would then be converted into s-expressions. The idea being, if I recall correctly, that you could have different m-expressions to suit different tastes.

In any case, a friend and I did something similar in making a toy language that would be rewritten to scheme. We got bored of it pretty quickly, but in the stuff we did get done, we didn't run into too many problems.

lmf said...

Thanks to you all for your comments.

@Anonymous Not everyone is looking for a lisp. Surely you have to believe that Clojure offers more than the ability to write macros.

@Mike Awesome. It's not Clojure, but it seems to do most of what I need in a language, so I'll have to give it a try.

@Simon You're right, I should just call it a DSL.

@coco See my answer to Anonymous.

Also: my DSL would not be for me, it would be a tool that I could use to show Clojure to scientists. I don't know how much you've worked with scientists, but F# would be far outside the realm of possibility. I'd be satisfied with reading code that uses recursion instead of for loops. These are people who write programs because they have to, not because they want to, so it would have to be close to what they already know.

@Andrew That's interesting. I've never heard of m-expressions.

ang said...

"I don't know how much you've worked with scientists, but F# would be far outside the realm of possibility"...is it a joke???...f# is more used in the scientist world than clojure, and actually the main contracts for computing scientists is for f# programmers, cambridge has contracted several f# programmers for biology and DNA researchs and for numerical computng too...actually f# is really well suited for numerical computing, in that side is better a static type language than a dynamic, about recursion...well, recursion is part almost any functional language, actually, the clr and mono are best suited for recursion than the jvm, because this come with tail call optimization, so the recursion is more elegant in f# than in clojure (not so elegant as haskell but is really good), and you've pattern matching, a incredible feature used with recursion...give it a try (or to haskell) and maybe you like it...now..I really love clojure too, but basicly I love clojure because is homoiconic and has the most powerfull computing invention...macros...and I'm not sure if a python implementation would have them...

lmf said...

"f# is more used in the scientist world than clojure,"

I'm not sure what to make of that comparison. If you compare to languages like Fortran, C++, Matlab and R, neither is used much at all.

"and actually the main contracts for computing scientists is for f# programmers, cambridge has contracted several f# programmers for biology and DNA researchs and for numerical computng too"

I'm sure there are domains where F# is used, but my area (statistical analysis) is not one of those areas, at least I've never been looking at someone's code and run across F#. I just do not see any chance that they'd be willing to learn F#.

Plus I love Clojure, so that's the language I will promote to others. I'm addicted to s-expressions.

Unknown said...

someone started it some time ago
https://github.com/apatil/pleajure

Unknown said...

clojure has no reader macros like common lisp but reader is modificable by users using its java guts:
http://briancarper.net/blog/449/clojure-reader-macros

Anonymous said...

Sounds you don't want closure in the first place, but more something like: http://nimrod-code.org/

Which also happens to get rid of the dreaded JVM...

Anonymous said...

Among the various techniques some of the aspects of google, eg, organic search, PPC
marketing, CTR, CPC, SEM, ROI, keyword density,
long-tail keywords, etc. And biggest online encyclopedia in the world,
is one big name in the google market that have been successfully operating in India, UK, America and Australia for
quite some years now. And YES my full version of GSA Website Submitter.
If you have an HTML sitemap that guides search engines to your site.


Feel free to surf to my site indianapolis search engine optimization

Anonymous said...

It is a must for you to find what people are really searching
for. Before it could take me up to two weeks to find the things we need in
search. Using these 3 simple tips, businesses of any size can get started on an effective
video marketing campaign to add to their current Business strategy.


my page; keyword search engine ranking