Porting Minilight to Clojure

6 views
Skip to first unread message

Mark Reid

unread,
Apr 7, 2009, 4:43:37 AM4/7/09
to Clojure
Hi,

In the interests of learning Clojure I thought it would be fun to port
the Minilight renderer to Clojure and write about the steps along the
way. If you're interested you can have a look at my first post here:

http://mark.reid.name/sap/minilight-clojure-vectors.html

I've not programmed in a Lisp-like before (aside from hacking the
odd .emacs files) and one thing I've noticed is just how flexible this
type of language is. The downside, of course, is that there are many
ways to do things sub-optimally or inelegantly so I welcome any
feedback.

Regards,

Mark.
--
http://mark.reid.name

Laurent PETIT

unread,
Apr 7, 2009, 5:35:51 AM4/7/09
to clo...@googlegroups.com
Hello Mark,

That's interesting, keep us informed of your progress!

Since you say you welcome any feedback, here are my remarks :

 * namespace names: you could maybe use more qualified names, e.g. qualifying them maybe with your own reversed namespace ( vec -> com.reid.vec ). Indeed, one of the interests of namespaces is to avoid name clashes, and it feels to me like creating namespaces of just one segment with such generic names such as vec may not scale well, even for personal work ?

* you have a file named test/test.clj . The corresponding namespace declaration should then be (ns test.test ...) instead of (ns test ...).

 * function calls in namespaces : your namespace 'test directly executes a call. This would be problematic for people using IDEs that automatically regularly auto-compile or auto-load files to give user error/warning feedback.
One alternative solution could be to just guard the call against compilation by checking the value of the *compile-files* global var :
(when-not *compile-files*
  (run-tests 'test.vec))
Another alternative could be to completely get rid of the immediate call to run-tests and place it instead in a -main method, so that the ns can be used as an independent executable file:

(ns test
  (:gen-class)
  (:use test.vec)
  (:use clojure.contrib.test-is))

(defn -main [] (run-tests 'test.vec))


HTH,

--
Laurent

Mark Reid

unread,
Apr 8, 2009, 6:56:14 AM4/8/09
to Clojure
Hi Laurent,

Thanks for the feedback regarding namespaces. That's exactly the sort
of thing I wasn't sure I was doing correctly.

I currently don't use an IDE that automatically compiles files so
wasn't aware of that problem. I prefer the solution that defines a
main method. My only question now is, if I don't want to compile the
test class, how do I call the main method from the command line?

Regards,

Mark.
--
http://mark.reid.name

Laurent PETIT

unread,
Apr 8, 2009, 7:11:06 AM4/8/09
to clo...@googlegroups.com
Hello,

function -main is a regular function, so the following works :
"
$ echo "(ns test (:gen-class)) (defn -main [] (println 1))" > test.clj
$ java -cp clojure.jar clojure.main -i test.clj -e "(test/-main)"

1
"

HTH,

--
Laurent

2009/4/8 Mark Reid <mark...@gmail.com>
Reply all
Reply to author
Forward
0 new messages