Re: loop-recur for string handling

2009-09-18 Thread Jonathan Smith
I find loop recur kind of hard to follow sometimes I was browsing through this pdf the other day: http://www.cs.umbc.edu/331/resources/papers/Evolution-of-Lisp.pdf And I found the tail recursive definition of common lisp/scheme style do. Thoroughly intrigued, I implemented it: (defmacro cl-

Re: loop-recur for string handling

2009-09-17 Thread Adrian Cuthbertson
There's also re-split in str-utils in clojure.contrib; (use 'clojure.contrib.str-utils) (re-split #"\s" "The quick brown fox") => ("The" "quick" "brown" "fox") You can then use all the good clojure collection functions; (def words (re-split #"\s" "The quick brown fox")) (some #{"brown"} words)

Re: loop-recur for string handling

2009-09-17 Thread Timothy Pratley
Also keep in mind that for string operations the Java String provides a lot of built in functionality: (let [s "the quick brown fox"] (.substring s (.indexOf s "brown"))) "brown fox" And you could simply ask the regular expression to find what you want: (re-find #"brown.*" "the quick brown fox")

Re: loop-recur for string handling

2009-09-17 Thread dreish
I think you're looking for something more like this: (use '[clojure.contrib.str-utils :only (str-join)]) (def mystr "the quick brown fox") (defn split-at-word [text keyword] (str-join " " (drop-while (partial not= keyword) (re-seq #"\w+" text user=> (split

Re: loop-recur for string handling

2009-09-17 Thread Baishampayan Ghose
Aridaman Pandit wrote: > 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 purpo

Re: loop-recur for string handling

2009-09-17 Thread Aridaman Pandit
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 ever

Re: loop-recur for string handling

2009-09-17 Thread Baishampayan Ghose
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.CharSeq

loop-recur for string handling

2009-09-17 Thread Aridaman Pandit
Hi everyone 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 (myse