History always repeats itself and sometimes that's good. Here's a second chance to be part of it: tmdtc.com
Showing posts with label clojure. Show all posts
Showing posts with label clojure. Show all posts

Friday, 4 September 2009

From OO to List style: my notes

I've continued development with Clojure and Jwt, and I got stuck: how do I implement my app without class definition and instance variables? It's not hard, but I had to get used to it. You'll find my notes here. Feedback welcome!

Wednesday, 26 August 2009

Jwt and Clojure

I've experimented with Jwt and Clojure, and put my findings on the web at
http://www.nsa.be/index.php/eng/Blog/Using-Jwt-yes-it-s-a-J-with-Clojure. If you're into web development you might be interested!

Tuesday, 10 March 2009

Generate a random string in Clojure

In my quest to learn Lisp, I discovered Clojure, a List inspired language on the JVM. I really like it and hope to be able to use it more and more.
Here's a code snippet to generate a random string in Clojure. This is something I end up using a many projects. This is a version that is not made to be the shortest, but the most readable. And as you can see, access to Java's classes and libraries is very easy:


:use java's random generator
(def random (java.util.Random.))
;define characters list to use to generate string
(def chars
(map char (concat (range 48 58) (range 66 92) (range 97 123))))
;generates 1 random character
(defn random-char []
(nth chars (.nextInt random (count chars))))
; generates random string of length characters
(defn random-string [length]
(apply str (take length (repeatedly random-char))))


Suggestions to improve the code are welcome, I'm still a newbie in Lisp-style programming and Clojure!