Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

applying clojure

Tags:

clojure

I have been following clojure for some time, and some of its features are very exciting (persistent data structures, functional approach, immutable state). However, since I am still learning, I would like to understand how to apply in real scenarios, prove its benefits and then evolve and apply for more complex problems. i.e. what are the easy wins with clojure (e.g. in an e-commerce setup) that can be used to learn as well as ascertain its benefits.

I have investigated clojure based web frameworks, but I am not keen on them, as they need hand-written javascript (as against gwt). So for me, it is more about backend processing. Can someone explain where they applied clojure (in real deployments), and how did it prove useful (and the cons, if any, of using clojure)

Further analysis: Lazy evaluation is an oft example of power of Lisp. Clojure being a Lisp, offers the same advantage. So, a real world example of such an application (in context of clojure) would help me gain insight.

like image 789
142857 Avatar asked Sep 18 '11 09:09

142857


People also ask

What is apply in Clojure?

A big difference between Clojure and CL is that Clojure is a Lisp-1, so funcall is not needed, and apply is only used to apply a function to a runtime-defined collection of arguments. So, (apply f [i]) can be written (f i).


1 Answers

You have mentioned that you work with CSV files. I found these to be very helpful, because I had to parse a csv file -- used clojure-csv; then extract certain columns from that csv file using sequence functions; interleave http form field names using zipmap; and then make http calls to an ASP application using clj-http.client.

(def accumail-url-keys ["CA", "STREET", "STREET2", "CITY", "STATE", "ZIP", "YR", "BILL_NO", "BILL_TYPE"] )
.
.
.

(defn ret-params 
    "Generates all q-parameters and returns them in a vector of vectors."
    [all-csv-rows]
    (reduce
      (fn [param-vec one-full-csv-row]
        (let [q-param (zipmap accumail-url-keys one-full-csv-row)
              accu-q-param (first (rest (split-at 3 q-param)))
              billing-param (first (split-at 3 q-param))]
          (conj param-vec [accu-q-param billing-param])))
      []
      all-csv-rows))

That project was an accelerated Clojure learning exercise.

Two sites 4Clojure.com and http://www.cis.upenn.edu/~matuszek/cis554-2010/Assignments/clojure-01-exercises.html are good places to start working on Clojure exercises. You can build on those.

Also the Clojure Google Group is a very helpful place to get information.

The Univ of Penn CIS exercises, as simple as they might seem, have given me a lot to digest, especially getting the skeleton of a tree, and recently the skeleton problem got a long discussion in the Google Clojure group.

Good luck. cmn

like image 135
octopusgrabbus Avatar answered Sep 28 '22 07:09

octopusgrabbus