Hi.

I have just started learning Clojure and I am really enjoying
myself. However, I am still getting to grips with the workings of its
concurrency model, so please excuse me if my question seems too
obvious.

I have some code that reads data from a file, parses it and generates
a CSV file. The flow is as follows:

<code>
(use 'clojure.contrib.duck-streams)
(use 'clojure.contrib.pprint)

(defn parse-line [s]
  (cl-format nil "~{\"~A\"~^,~}" (into [] (.split s ";"))))

(let [input-seq (for [line (read-lines "input.dat")]
                  (parse-line line))]
  (write-lines "out.CSV" input-seq))
</code>

Now the question:

I would like to generate log entries for any malformed lines occurring
in the input file. Once of the ways might be to do this in parse-line
using clojure.contrib.logging as follows:

<code>
(use 'clojure.contrib.logging)

(defn parse-line [s]
  (let [cs (into [] (.split s ";"))]
    (if (= (count cs) 5)
      (cl-format nil "~{\"~A\"~^,~}" cs)
      (error "Incorrect number of columns in file."))))
</code>

Since FOR returns a lazy sequence of the results, is this function
safe?  (Seeing that it is not side-effect free?)

BTW:
  clojure.contrib.logging indicates that it can use an agent for
  logging. Is my assumption that invoking the logger (with or without
  an agent) within a function would still mean that the function has
  side-effects correct?

Martin.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to