New personal site

After years thinking about it, finally I’ve done it: I’ve registered a custom domain (a simple URL redirect) and I’ve create an app on the popular cloud hosting site Heroku: it uses the new Clojure support feature and the new (and cool) Clojure mini MVC Framework Noir.

The site is a bit slow the first time you visit it, because the app is pushed out of cache after a period of inactivity, but man, it’s free!
I really like the site layout (and Jquery is too cool). What do you think about it? Let me know! Ah, here is the url, visit it!

clj3D: The first (serious as a Monkey) Clojure 3D library

As we should know, a language can’t be neither omni-comprehensive nor usable in every situation. There are some kind of areas (e.g. graphics and speed-critical software) where Java sucks badly. Yeah, there are some interesting projects but they aren’t nearly comparable to the C or C++ ones. The world of 3D graphics is very fascinating and it’s my primary goal trying to find a satisfying job into it. But, what all this stuff have to do with Clojure?
Well, a Clojure flaw was a lack of 3D graphics library. I’m not talking about idiomatic wrappers (like the awesome penumbra) around OpenGL calls, since these kind of library are too low level (in my opinion). We need something to  easily create and transform 2D and 3D objects using some solid foundations.

In my free time I’m working on this kind of library, my project was called clj-3D (not too much original, I know :D). As the documentation says “Clj3D is a Clojure graphic library for manipulating 3D and 2D objects. It aims to be the Clojure standard in 3D and 2D rendering”: I think that every attempt to enrich the awesome language Clojure is, worth the effort.
Clj3D mesh together to worlds: the former is the JMonkeyEngine, a wonderful project that is trying to make Java less horrible into 3D Graphic field; the latter is PLaSM, a geometric language developed within my university.

With clj3D you are able to display something with few lines of code: you can write your own 3D models and display it directly with clj3D! Check this out:

(use '(clj3D fenvs viewer) :reload)
(view (cube 1))

This display a light gray 1x1x1 cube. clj3D is under massive development, so only few subsets of PLaSM and JMonkey have been wrapped/coded. I hope that this project will be embraced by the Clojure community, and made better as well. For the usage and installation the github page is always “work in progress”, but you can use leiningen to satisfy the dependencies and for compile the java extra classed needed. Actually clj3D is tested only under Mac OS X, so feedbacks are welcome! I will push monthly releases on Clojars, so stay tuned!



A bit of Clojure magic and high order functions are served

Hi guys, what’s up?

I’m a little busy right now. I’ve started what is probably going to be my last semester of university courses and I’ve started coding a Clojure 3D library (coming soon on these screens). But this is the good time to take a break and write something on this blog. A really cool (and useful) features of Haskell is the ability to use High Order Functions. Take a look to this simple Haskell snippet:

> :t take
take :: Int -> [a] -> [a]

> :t take 10
take 10 :: [a] -> [a]

> :t take 10 ['a'..'z']
take 10 (enumFromTo 'a' 'z') :: [Char]

As you can see the arguments are “eaten” one by one in a way that remember the dear old Pacman. In a nutshell take 10 returns a function that applied to a sequence return a result. Simple enough, isn’t it?
Unfortunately this doesn’t happens by default in Clojure. Observe this little function:

(defn sum [a b] (+ a b))

If you’ll try to invoke

(sum 1)

you we’ll get the following:

Wrong number of args (1) passed to: user$sum

This is absolutely normal, since it is the Clojure default behaviour. Googling and Stack-overflowing around a bit, I came up to a simple snippet to implement with a macro the required behaviour:

(defmacro defn-decorated
  "like defn except it accepts an additional vector of
   decorator functions which will be applied to the base definition.
   the decorators are applied in left-to-right order."
  {:author "Robert McIntyre"
   :arglists '[[name [modifers*] doc-string? attr-map? [params*] body]
	       [name [modifers*] doc-string? attr-map? ([params*] body) + attr-map?]]}
  [fn-name decorators & defn-stuff]
     (defn ~fn-name ~@defn-stuff)
     (alter-var-root (var ~fn-name) (reduce comp identity (reverse ~decorators)))
     (var ~fn-name)))

(defn curry**
  [number-of-args f]
    ([& args]
       (let [number-of-inputs (count args)]
	 (if (= number-of-inputs number-of-args)
	   (apply f args)
	   (curry** (- number-of-args number-of-inputs)
		    (apply (partial+ partial+ f) args)))))))

(def curry* (curry** 2 curry**))

(By the way you can find the complete clj file here.) Here’s an example of application:

(defn-decorated sum [(curry 2)] [a b] (+ a b))

But a thing I didn’t like was the explicit passing of the number of argument which the function is composed, so I wrote my own macro:

(defmacro defn-ho
  [fn-name & defn-stuff]
  (let [number-of-args (count (first defn-stuff))]
    `(defn-decorated ~fn-name [(curry* ~number-of-args)] ~@defn-stuff)))

With this simple add-on, you can easily write any kind of high order function in a way like this:

(defn-ho new-sum [a b c] (+ a b c))

I haven’t tried it in particular situations (e.g. with destructuring) but don’t expect it to work with function with multiple arity: indeed, but really  you will need to create n-arity high order function??

Feedback are welcome, as always!



The power of the big


I’ve been quoted into a sort of report about F# and XNA development (Btw, I’ve only tweaked a bit a source code found on the net, just to learn a bit F# and XNA):

I’m really surprised due to the echo of F# and XNA all over the internet… I mean, I’ve spent hours playing and writing about other awesome functional languages (Haskell, Scheme, Common Lisp, Clojure) but I’ve never been quoted, because “Speaking about Common Lisp and other crazy stuff is not cool”. This is sad, really sad.

On the other side, I’m very proud of have been cited somewhere 😛 (despite I haven’t done nothing special)