Created
March 13, 2011 17:09
-
-
Save daviddavis/868264 to your computer and use it in GitHub Desktop.
palindromes.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exception in thread "main" java.lang.Exception: Unable to resolve symbol: re-gsub in this context (palindromes.clj:27) | |
at clojure.lang.Compiler.analyze(Compiler.java:5205) | |
at clojure.lang.Compiler.analyze(Compiler.java:5151) | |
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3036) | |
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5371) | |
at clojure.lang.Compiler.analyze(Compiler.java:5190) | |
at clojure.lang.Compiler.analyze(Compiler.java:5151) | |
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:4670) | |
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:4328) | |
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3173) | |
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5367) | |
at clojure.lang.Compiler.analyze(Compiler.java:5190) | |
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5357) | |
at clojure.lang.Compiler.analyze(Compiler.java:5190) | |
at clojure.lang.Compiler.analyze(Compiler.java:5151) | |
at clojure.lang.Compiler$HostExpr$Parser.parse(Compiler.java:798) | |
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5369) | |
at clojure.lang.Compiler.analyze(Compiler.java:5190) | |
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5357) | |
at clojure.lang.Compiler.analyze(Compiler.java:5190) | |
at clojure.lang.Compiler.access$100(Compiler.java:35) | |
at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:438) | |
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5369) | |
at clojure.lang.Compiler.analyze(Compiler.java:5190) | |
at clojure.lang.Compiler.analyze(Compiler.java:5151) | |
at clojure.lang.Compiler.eval(Compiler.java:5428) | |
at clojure.lang.Compiler.load(Compiler.java:5857) | |
at clojure.lang.Compiler.loadFile(Compiler.java:5820) | |
at clojure.main$load_script.invoke(main.clj:221) | |
at clojure.main$script_opt.invoke(main.clj:273) | |
at clojure.main$main.doInvoke(main.clj:354) | |
at clojure.lang.RestFn.invoke(RestFn.java:409) | |
at clojure.lang.Var.invoke(Var.java:365) | |
at clojure.lang.AFn.applyToHelper(AFn.java:163) | |
at clojure.lang.Var.applyTo(Var.java:482) | |
at clojure.main.main(main.java:37) | |
Caused by: java.lang.Exception: Unable to resolve symbol: re-gsub in this context | |
at clojure.lang.Compiler.resolveIn(Compiler.java:5677) | |
at clojure.lang.Compiler.resolve(Compiler.java:5621) | |
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:5584) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns palindromes | |
(:require clojure.contrib.string) | |
(:require clojure.contrib.str-utils)) | |
(def text | |
(str "I'll just type in some example text here and embed a little | |
palindrome - A man, a plan, a canal, Panama! - I expect that will be | |
the longest palindrome found in this text. | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | |
Integer volutpat lorem imperdiet ante bibendum ullamcorper. Mauris | |
tempor hendrerit justo at elementum. Vivamus elit magna, accumsan id | |
condimentum a, luctus a ipsum. Donec fermentum, lectus at posuere | |
ullamcorper, mauris lectus tincidunt nulla, ut placerat justo odio sed | |
odio. Nulla blandit lorem sit amet odio varius nec vestibulum ante | |
ornare. Aliquam feugiat, velit a rhoncus rutrum, turpis metus pretium | |
dolor, et mattis leo turpis non est. Sed aliquet, sapien quis | |
consequat condimentum, sem magna ornare ligula, id blandit odio nisl | |
vitae erat. Nam vulputate tincidunt quam, non lacinia risus tincidunt | |
lacinia. Aenean fermentum tristique porttitor. Nam id dolor a eros | |
accumsan imperdiet. Aliquam quis nibh et dui ultricies cursus. Nunc | |
et ante non sapien vehicula rutrum. Duis posuere dictum blandit. Nunc | |
vitae tempus purus.") | |
) | |
(defn sanitize [n] | |
(re-gsub #"[^a-z]" (lower-case n)) | |
) | |
(defn palindromep [n] | |
(= (sanitize n) (reverse (sanitize n))) | |
) | |
(println (sanitize text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment