Ever wanted to write a script once and then run it using the Clojure REPL for Android? I was recently asked about this via e-mail, and I thought it would be good to make a note of it here.
First, you will need to write your script and get it onto your phone in a
world-readable location. Usually, the SD card should work out well enoughi,
which is generally mounted at
/sdcard. Therefore, if you transfer your
coolscript.clj to the SD card, it should show up at
Now, all you need is the
load-file command. To run the script
above, you would just enter:
Note there is one important limitation to this approach. It does not change the path for which scripts are looked up. If your script requires searching for other files that define namespaces, it generally will not work. Adding directories to the search path is proposed feature that would be nice to add.
Behind the scenes
I have not abandoned the REPL. Since the Conj, I have been working on the REPL to help get some more feedback to the Clojure/dev team to improve Clojure on Android. At the Conj, I announced Neko, the Clojure/Android Toolkit. I have since updated it to be compatible with the latest versions of both Clojure and the Android SDK. I also now have a version of Clojure for Android that is compatible with the latest 1.4 developments.
Please stay tuned for more Clojure/Android news and a Clojure/conj wrap-up.