I know you are asking about refs, but you might want to think about
using reduce to walk the line-seq. the nature of reduce lets you have
access to the line-seq, two lines at a time no need for a ref.
On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle <[EMAIL PROTECTED]> wrote:
> I am parsing a file and to compare the current line
> with the previous line of the file. I am using line-seq
> to go thru the file and I thought I would create a
> ref to store the previous line. When I want to update
> the previous line value I can't seem to do it. I've
> never used refs before so I'm sure I'm doing something
> very stupid.
>
> (defstruct line :lat :lon :name)
>
> (defn convert [file]
> (let [prev-line (ref (struct line))]
> (with-open [r (reader file)]
> (doseq [l (line-seq r)]
> (let [ps (split #"," l)
> c-line (struct line (ps 0) (ps 1) (ps 2))]
> (if (not= c-line @pre-line)
> (do ; do stuff here then update pre-line
> (dosync ref-set pre-line (apply struct line (vals c-line)))
> (println @pre-line)))))))) ; this prints out all nils
> doesn't seem to work
>
>
>
> Sorry if this email is not formatted correctly. Something is wrong with my
> browser
> currently typing in a textarea. Thanks.
>
>
>
> >
>
--
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---