Hi Thanks for the reply. I understand the code that you have given. Actually I also wanted it to be stored into some variable (if not the same) everytime I run it. Suppose I am matching for keyword "brown" and I want to store everything after "brown". So for that purpose I wanted to chop off everything that comes before "brown" and keep the rest. Can you help me in doing that. I know its a bit silly thing but the thing is I am very new to it and still in the C/C++ like orientation. But the thing is how do I assign it some keyword or something so that I can call it as and when required.
On Sep 17, 3:53 pm, Baishampayan Ghose <b.gh...@ocricket.com> wrote: > Aridaman, > > > > > I am very new to clojure and have worked previously on C/C++ > > > I wanted to do some string operations, where I can match occurrence of > > a particular string. However, I get this error everytime. > > > java.lang.ClassCastException: clojure.lang.Var cannot be cast to > > java.lang.CharSequence (myseq.clj:0) > > > Here is the code, which is quite lame but is just made for learning > > purpose. > > > (def myseq "the quick brown fox") > > (loop [word myseq] > > (if (= (first (re-seq #"\w+" word)) "fox") (println "Yeah!!") > > (recur (def myseq (apply str (interpose " " (rest (re-seq #"\w+" > > myseq)))))))) > > Your syntax for loop/recur is completely wrong :) > > I think you wanted to do something like this - > > (def myseq "the quick brown fox") > > (loop [s myseq] > (if (= (first (re-seq #"\w+" s)) "fox") > (println "Yeah!") > (recur (apply str (interpose " " (rest (re-seq #"\w+" s))))))) > > In short, you don't def the value of myseq again when you recur. > Remember that Clojure is a (mostly) functional language where mutation > is discouraged. Whenever you see yourself mutating things, you should > double check the code. > > def is for top-level variable declarations only. You can use let for > lexical bindings, that too when required. > > Have fun :) > > Regards, > BG > > -- > Baishampayan Ghose <b.gh...@ocricket.com> > oCricket.com > > signature.asc > < 1KViewDownload --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---