clojure - Holding onto the head of sequence when using "rest" -


i parsing big csv file , using first line of keys records. csv file like:

header1,header2 foo,bar zoo,zip 

i end lazy seq like:

({:header1 "foo" :header2 "bar"},  {:header1 "zoo" :header2 "zip"}) 

the code working fine, not sure if in following function holding head of "lines" or not.

(defn csv-as-seq [file]   (let [rdr (clojure.java.io/reader file)]     (let [lines (line-seq rdr)          headers (parse-headers (first lines))]       (map (row-mapper headers) (rest lines))))) 

can please clarify?

yes, expression syntactically says hold head

(let [lines (line-seq rdr) 

though in case should away because no references lines , headers after call map , clojure compiler starting 1.2.x includes feature called locals clearing: sets locals not used after function call nil in preamble function call. in case set lines , headers nil in local context of function , gcd used. 1 of rare cases clojure produces bytecode cannot expressed in java.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -