Pharen: A lisp that compiles to PHP
scriptor.github.com
scriptor.github.com
Yes there are a lot of issues with cross-language compilers. That said, Coffeescript: http://coffeescript.org, which compiles its own language to Javascript has had a lot of success and is being used in production. So it's at least possible to use languages like this.
The extra layer of abstraction is a big hurdle. When debugging you have to find the source of the problem in the PHP, though ideally after that you can just find the matching Pharen code and go from there. One of the things on my todo list is to have at least a rough line-to-line tracker built, so that it could at least tell you the general location a problem happened, if not the exact line.
Translating docs and example code for existing libraries into Pharen is a bigger issue, I think. Mainly because Pharen emphasizes a functional style of coding while most PHP code assumes you are doing things imperatively. This is something Clojure has to deal with in terms of Java interop so again it shouldn't be too hard to get around.
In terms of efficiency there is tail recursion optimization (converts a recursive function to having a while loop at the end) and a persistent sequence library in the works that would make functional looping through a list about as fast as imperative iteration. More aggressive optimizations might come in the future.
If you're interested, feel free to contribute: http://scriptor.github.com/pharen/contribute.html. If you use IRC you can come hang out (or berate me personally) on #pharen on Freenode. Any suggestions or ideas are welcome.
You could always just add the S-Expression that became the php code as a comment. From there it should be trivial to find it in the Pharen code.
Other than that, Pharen looks very interesting. A minor detail is that I didn't yet figure out how to call static methods of external PHP classes.
One thing I don't understand is why there is special unnatural-looking syntax for dictionaries. It is inconsistent that comma=whitespace everywhere else. Perhaps something like:
(array "a"=>1 "b"=>2)
Note that this currently compiles to array("a", =>1, "b", =>2)
What do you mean by it's inconsistent? Commas are the same both in dictionaries and anywhere else, they're completely optional.
It gives you a chance to use Lisp's syntax and mentality if you're stuck with PHP on the backend. Moreover, you have features like macros and lexical scope, which can be useful.
I just wondered if it had been built for a specific project and if so what problems it was trying to solve.
It's funny - I've spent the past few years thinking about high-level languages that would compile down to lisp. Recently I've seen a number that go the other way.
Cheers!
Efficient sequences are what I'm working on right now, particularly trying to make persistent versions of the major data structures in PHP.
Tail calls are another thing, though with PHP 5.3's gotos they could be done (who'd have thought that feature would ever be useful?) Could you elaborate on how I could improve efficiency for macros?
What are the major differences between Pharen and Lisphp?
(covered here:)
Pharen generates regular PHP source files that you can then throw wherever PHP works.
I think, strictly, the former.
(I actually laughed out loud at this :_)
Other than that Pharen is still pretty new and nowhere near the same level as mature lisps. Making debugging and interop with 3rd party libraries easier are the main long-term goals, so maybe after that it'll be at least a little viable.
My current project involves generating php from a declarative definition and this could be just the right tool for the job! Maybe it will make switching to common lisp a lot easier once I learned enough of it :D
So that it would just generate the Pharen code resulting from the expansion? Unfortunately, not yet. As soon as a macro is done executing it returns the node tree itself, which is then compiled. There might be a way to hack macro-expand in though.
Let me know how trying to work it into your project goes! I'll be glad to help with any problems that come up.
The project is on GitHub, so submitting patches is very easy.
(:some-list 1)
Here, some-list is just a variable while the : prefix tells Pharen that you are trying to index into it.