On Sat, Jan 17, 2009 at 9:09 AM, mbrodersen <morten.broder...@gmail.com>wrote:

>
> Hi
>
> I am having fun learning Clojure but have a problem with the following
> code. If you run the code with the ;OK removed then it works. If you
> run the code with ;ERROR removed then it doesn't.
>
> The code is my own implementation of splitting a string into
> individual words (just a learning exercise). The error message is:
>
> java.lang.IllegalArgumentException: No matching method found:
> isWhitespace (error.clj:0)
>
> Which is strange because the ;ERROR line has nothing to do with
> isWhitespace?
>
> Any help would be appreciated.
>
> Thanks
> Morten
> -----------------------------------------------------
>
> (defn line-skip-ws [line]
>        (cond
>                (not (first line))
>    ""
>                (Character/isWhitespace (first line))   (line-skip-ws (rest
> line))
>                true
>            (apply str line)))
>
> (defn line-split-1 [word line]
>        (let [c (first line)]
>                (println "line-split-1" "word:" word "line:" line "c:" c
> "class:" (class c))
>                (cond
>                        (not c)
> [word ""]
>                        (Character/isWhitespace c)      [word (apply str
> line)]
>                        true
>  (line-split-1 (str word c) (rest line)))))
>
> (defn line-split [line]
>        (let [split (line-split-1 "" (line-skip-ws line))]
>                (if (= (first split) "")
>                        [""]
> ;ERROR          (concat [(first split)] (line-split (rest split))))))
> ;OK                     (concat [(first split)] []))))
>
> (doseq [x (line-split "  Hello   world!  ")] (println (format "\"%s\""
> x)))
>

Hi Morten,

When you call line-split with (rest split), you're passing a Clojure
sequence of characters, not a string. Then line-skip-ws calls isWhitespace
with the sequence and Java doesn't know what to do with it. Try converting
(rest split) to a string using (apply str (rest split)).

Shawn

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