Beginner question to a error please

2010-12-20 Thread uap12
Hi,
I just started a hobby project, it download a webbpage, and extract number 
data witch exits between brStart rad:/SPAN   --and --  /TD
Example
brStart rad:/SPAN01 20 20 52 32 85 89/TD

Everything works fine exept -main witch gives a error i don't understand.
Becurse i try to learn Clojure, i like to now what's wrong a way :)

Here is my code

(ns com.persson.extract
;(:import )
;(:require )
)

(defn remove-endlines [file]
  (filter #(not= % \newline)
(filter #(not= % \return) file)))

(defn get-file-without-endlines[file]
(remove-endlines (slurp file) ))

(defn -main[]
(re-find #brStart rad:\/SPAN*.\/TD (get-file-without-endlines 
E:/testing/data/1999_1.txt )))

And here is the error
---
com.persson.extract= (-main)
#CompilerException java.lang.ClassCastException: clojure.lang.LazySeq 
cannot be cast to java.lang.CharSequence (NO_SOURCE_FILE:117)

Best regards
Anders

-- 
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

Re: Beginner question to a error please

2010-12-20 Thread Laurent PETIT
2010/12/20 uap12 anders.u.pers...@gmail.com

 Hi,
 I just started a hobby project, it download a webbpage, and extract number
 data witch exits between brStart rad:/SPAN   --and --  /TD
 Example
 brStart rad:/SPAN01 20 20 52 32 85 89/TD

 Everything works fine exept -main witch gives a error i don't understand.
 Becurse i try to learn Clojure, i like to now what's wrong a way :)

 Here is my code
 
 (ns com.persson.extract
 ;(:import )
 ;(:require )
 )

 (defn remove-endlines [file]
   (filter #(not= % \newline)
 (filter #(not= % \return) file)))

 (defn get-file-without-endlines[file]
 (remove-endlines (slurp file) ))

 (defn -main[]
 (re-find #brStart rad:\/SPAN*.\/TD (get-file-without-endlines
 E:/testing/data/1999_1.txt )))

 And here is the error

 ---
 com.persson.extract= (-main)
 #CompilerException java.lang.ClassCastException: clojure.lang.LazySeq
 cannot be cast to java.lang.CharSequence (NO_SOURCE_FILE:117)


The return value of get-file-without-endlines will be a seq of Chars, while
re-find expects a CharSequence (generally a String).
So to follow in the spirit of your example, you'd have to first convert your
seq of Chars back into a string, e.g. via
(apply str (get-file-without-endlines ))

HTH,

-- 
Laurent


 Best regards
 Anders

  --
 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.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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

Re: Beginner question to a error please

2010-12-20 Thread uap12
Tanks very mutch for the help.
/Anders

-- 
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

Re: Beginner question to a error please

2010-12-20 Thread Ken Wesson
On Mon, Dec 20, 2010 at 10:27 AM, uap12 anders.u.pers...@gmail.com wrote:
 Tanks very mutch for the help.
 /Anders

Of course (apply str ...) will suck the whole file into ram all at
once, eagerly. If it's a multi-gigabyte file expect OOME. It would be
nice if there was a variation on re support that worked on arbitrary
seqs -- seqs of Characters, at least, and preferably (with suitable
additional features) perhaps also seqs of other objects. (Ultimately,
it always boils down to a test of whether a particular object meets
some criterion. Sometimes that's equality with a particular other
object; sometimes membership in a range. Using = and, with ranges,
compare with the endpoints seems like it should generalize well, but
you might want to be able to supply a set of class-comparator pairs.
These could be combined into a multimethod under the hood that acts as
a global comparator during what followed. Ranges wouldn't always make
sense, such as for maps and sets; lists, seqs, and vectors might have
a default comparison that generalizes that for strings, though that
will wedge if two equal, infinite seqs ever get compared. Then again
so will =.)

-- 
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


Re: Beginner question to a error please

2010-12-20 Thread Laurent PETIT
2010/12/20 Ken Wesson kwess...@gmail.com

 On Mon, Dec 20, 2010 at 10:27 AM, uap12 anders.u.pers...@gmail.com
 wrote:
  Tanks very mutch for the help.
  /Anders

 Of course (apply str ...) will suck the whole file into ram all at


slurp will suffice to suck everything into memory


 once, eagerly. If it's a multi-gigabyte file expect OOME. It would be
 nice if there was a variation on re support that worked on arbitrary
 seqs -- seqs of Characters, at least, and preferably (with suitable
 additional features) perhaps also seqs of other objects. (Ultimately,
 it always boils down to a test of whether a particular object meets
 some criterion. Sometimes that's equality with a particular other
 object; sometimes membership in a range. Using = and, with ranges,
 compare with the endpoints seems like it should generalize well, but
 you might want to be able to supply a set of class-comparator pairs.
 These could be combined into a multimethod under the hood that acts as
 a global comparator during what followed. Ranges wouldn't always make
 sense, such as for maps and sets; lists, seqs, and vectors might have
 a default comparison that generalizes that for strings, though that
 will wedge if two equal, infinite seqs ever get compared. Then again
 so will =.)

 --
 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.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


-- 
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

Re: Beginner question to a error please

2010-12-20 Thread Ken Wesson
On Mon, Dec 20, 2010 at 3:55 PM, Laurent PETIT laurent.pe...@gmail.com wrote:


 2010/12/20 Ken Wesson kwess...@gmail.com

 On Mon, Dec 20, 2010 at 10:27 AM, uap12 anders.u.pers...@gmail.com
 wrote:
  Tanks very mutch for the help.
  /Anders

 Of course (apply str ...) will suck the whole file into ram all at

 slurp will suffice to suck everything into memory

True. You need a seq view of the file, perhaps with line-seq or
perhaps with a seq wrapper around the stream to get a char seq. The
latter can probably be hacked up fairly quickly using lazy-seq; it's
surprising it's not (to my knowledge) in core, really.

-- 
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