2008-04-06
| 13:50 | gomer-nyc | Hi there |
| 13:50 | gomer-nyc | I started learning Clojure yesterday, and loving it so far |
| 13:50 | rhickey_ | cool |
| 13:50 | gomer-nyc | I also don't know the Java Class Libs, so learning that also as I go (for example, Net access etc.) |
| 13:50 | gomer-nyc | anyway, I have a clojure language question |
| 13:51 | gomer-nyc | I have a working version of something I'm trying to achieve, but not sure whether this is the best implementation. |
| 13:51 | gomer-nyc | Rich, can I paste in the line of code and discuss? |
| 13:52 | rhickey_ | sure |
| 13:52 | gomer-nyc | cool; so what I'm doing is simply replacing one character with another in a string, and returning a string. Doing it like so: |
| 13:53 | gomer-nyc | (reduce (fn [x y] (str x y)) (replace {\space "+"} "new york, ny")) |
| 13:54 | rhickey_ | I presume you are avoiding String.replaceAll as an exercise? |
| 13:56 | gomer-nyc | Ha! didn't want to use java lib stuff, but that would prob be better :-) |
| 13:56 | rhickey_ | (apply str (replace {\space "+"} "new york, ny")) |
| 13:56 | rhickey_ | apply str is better than reduce with str |
| 13:56 | gomer-nyc | agreed |
| 13:57 | gomer-nyc | great, thanks |
| 15:01 | jonathan_ | ? why the difference on apply and reduce ? |
| 15:05 | jonathan_ | sorry, apply will get the whole list instead of recursing as with reduce. |