A very naive experiment on compiling Clojure to PHP. Hmmm...
Simple example of defining and cailling a function:
(ns examples.basic) (defn double [x] (* 2 x)) (println (str "Double 2 is... " (double 2)))
You can compile and run this with:
Which should output:
Double 2 is... 4
At the moment only the basic of Clojure have been implemented, but hopefully this will be a growing list.
- namespaces (with :use and :require)
- PHP integration
Integration with PHP is handled (like in ClojureScript) through the php import to each namespace. You can then reference any functions from the standard PHP distributions.
(println "Date is: " (php/date "dS F Y, H:i:s"))
Tests written with Midje and PHPUnit, run them with...
lein midje phpunit test/php
This is not meant to ever be an actually useful thing, compiling Clojure to PHP is insane. It's just a learning tool for me to get more familiar with Clojure.