devNoo

musings of a Software Developer

Seven languages in seven weeks: solutions for clojure day 1

| 0 comments

Clojure was a language I looked forward to learn about, mostly because I didn’t understand any code that was showed to me. The first day of clojure takes it slowly, but helps you get a grip on the lisp like jvm language. Installing clojure on windows was just extracting a zip file. In IntelliJ I installed the La clojure plugin. This seams to be a great plugin, although I only used its console feature, (is the autocomplete coming from clojure repl, or is it La console?).

Well the exercises where really small so this will be a very short entry.

Exercise 1

The first exercise is to great a function big that accepts a string and a number, and returns true if the length of the string is greater that the number:

Not much to explain here.

Exercise 2

The second exercise is to return the :list, :map, set or nil depending on the type of the collection parameter.

 

This method is just a nested if structure, so quite easy to understand when you get used to the lisp like syntax en structure.

Conclusion

I was a bid pessimistic about the readability of clojure code, but now finally see that it mostly comes from the completely different way of coding. I quite like the small things we did till now, but wonder how a bigger program will look like. In comparison to Erlang/Prolog I find that simple things are much easier to solve in Clojure than in those language.

For learning the language you should give4clojure a go, it is a great way to get the know clojure a bit.

Leave a Reply

Required fields are marked *.

*