Building regex pattern literals (Noob question)
I want to build a regular expression pattern literal (I think that's what they're called) like #"a.*" out of separate strings like "a" and ".*". user> (re-seq #"a.*" "bab") ; this is cool ("ab") user> (re-seq #(str "a" ".*") "bab") ; but this, in all its noobness, is not ; Evaluation aborted. user> #(str "a" ".*") # ; what is this thing? can I use it somehow? I appreciate the help. - Blaine --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Building regex pattern literals (Noob question)
I'm all straightened out. Thanks everyone. Very helpful. On Dec 3, 3:18 pm, Chouser <[EMAIL PROTECTED]> wrote: > On Wed, Dec 3, 2008 at 2:57 PM, Blaine <[EMAIL PROTECTED]> wrote: > > > I want to build a regular expression pattern literal (I think that's > > what they're called) like #"a.*" out of separate strings like "a" and > > ".*". > > > user> (re-seq #"a.*" "bab") ; this is cool > > ("ab") > > user> (re-seq #(str "a" ".*") "bab") ; but this, in all its noobness, is > > not > > ; Evaluation aborted. > > user> #(str "a" ".*") > > # ; what > > is this thing? can I use it somehow? > > It's a function! You could have built the same thing like this: > user=> (fn [] (str "a" ".*")) > # > > You can use it, but it has nothing to do with regex: > user=> (def thing #(str "a" ".*")) > #'user/thing > user=> (thing) > "a.*" > > It's just a function that returns a literal string. A "regex" in > Clojure/Java is actually a java.util.regex.Pattern: > user=> (class #"") > java.util.regex.Pattern > > To programmatically build one, you'll have to use that class directly, > or 're-pattern': > user=> (doc re-pattern) > - > clojure.core/re-pattern > ([s]) > Returns an instance of java.util.regex.Pattern, for use, e.g. in > re-matcher. > nil > user=> (re-pattern (str "a" ".*")) > #"a.*" > > ...so back to your original example: > user=> (re-seq (re-pattern (str "a" ".*")) "bab") > ("ab") > > But remember that you may need extra backslashes inside the "string" > parts, compared to the equivalent #"regex" literal. > > Or if each piece of your regex can stand alone, you could take > advantage of the fact that the .toString method on Pattern returns a > sufficiently escaped string: > > user=> (re-seq (re-pattern (str #"s" #"\w*")) "sue sang a song") > ("sue" "sang" "song") > > --Chouser --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: change in doto behavior
The example on http://clojure.org/jvm_hosted should reflect this. I'm not sure this is the proper venue to report such stuff. I've used this example (successfully) to convince those that normally walk away when I start talking about lisp to give clojure a look. I just cut and paste it into the repl. It may be boring, but when you have only seconds for the pitch... On Dec 2, 10:12 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote: > Yes.dotois more general now. The . is needed to indicate Java > interop calls becausedotocan do other things which are not Java > interop calls: > > (doto"double" println println) > double > double > -> "double" > > Stuart > > > Can someone tell me whether this change was intentional? In the > > 20080916 release, I get this: > > > user=> (doto(new java.util.HashMap) (.put "a" "b")) > > java.lang.IllegalArgumentException: No matching method found: .put > > java.lang.IllegalArgumentException: No matching method found: .put > > at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:44) > > at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28) > > at user.eval__4117.invoke(Unknown Source) > > at clojure.lang.Compiler.eval(Compiler.java:3891) > > at clojure.lang.Repl.main(Repl.java:75) > > user=> (doto(new java.util.HashMap) (put "a" "b")) > > {a=b} > > > In revision 1139, I get this: > > > user=> (doto(new java.util.HashMap) (put "a" "b")) > > java.lang.Exception: Unable to resolve symbol: put in this context > > (NO_SOURCE_FILE:2) > > user=> (doto(new java.util.HashMap) (.put "a" "b")) > > #=(java.util.HashMap. {"a" "b"}) > > > I'm using JRE 1.6.0.10. > > > Bill Smith --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: A newbie question on Agents and ants
Have you checked out: http://clojure.blip.tv/file/812787? Clojure's author talks about agents and the other concurrency support mechanisms in Clojure. The latter half of the talk is a walk-through of the ant simulation. It's really good presentation. - Blaine On Dec 7, 12:56 am, "Matthew Wyatt" <[EMAIL PROTECTED]> wrote: > Hi all, >I have a newbie question about Agents. I've been looking at the ants.clj > file:http://clojure.googlegroups.com/web/ants.clj?hl=en&gda=-X7f3joAAABoLi... > Most of it makes sense to me, but the use of Agents is confusing. For > example, the line: > (send-off animator animation) > associates the "animator" Agent with the "animation" function, which I > follow. But then the animation function looks like: > (defn animation [x] > (when running > (send-off *agent* #'animation)) > (. panel (repaint)) > (. Thread (sleep animation-sleep-ms)) > nil) > > That third line has me lost - I don't know what *agent* is. In Common Lisp, > that would indicate a global variable, but no such variable is declared (two > other functions, "evaporation" and "behave" have a similar call, and are the > only other references to *agent* in the file). I'm guessing it's some sort > of reference to the agent associated with the current Action, but where is > that documented? Secondly, why does the function immediately send off to > another agent? Is this in order to "loop" the function (that is, keep > spawning an Action to update the agent)? If that is the case, is the > Thread.sleep call in order to hold a reference to the agent so that the next > Action doesn't start immediately? >Thanks for your time helping a newb; I'm pretty excited about Clojure, > and can't wait to get my hands dirty with it. > -Matt --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Baltimore Functional Programming
Interested. On Nov 28, 10:05 pm, Ryan wrote: > I'm just south in Odenton, and definitely interested. I'll see if I > can't wrangle a few more peeps. -- 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
Re: Trying to get the ants demo to run on Windows
Hi there, I'm having almost the same problem. I'm trying to get the ants demo running in ubuntu, and I get Rob's second problem: user=> (def panel (doto (proxy [JPanel] [] (paint [g] (render g))) (.setPreferredSize (new Dimension (* scale dim) (* scale dim) java.lang.IllegalArgumentException: No matching method found: .setPreferredSize for class clojure.lang.Proxy__203 (NO_SOURCE_FILE:7) The rest of the file loads - if I run clojure from within slime I can individually compile the rest of the defns. (That said, I can no longer start clojure from within slime. After updating clojure it stopped working.) I'm at revision 1128 for clojure. I'm new to Java, so is it possible that I don't have some Swing/AWT thing installed? No complaint from: user=> (import '(java.awt Color Graphics Dimension) '(java.awt.image BufferedImage) '(javax.swing JPanel JFrame)) nil And, the java version, in case that's relevant: [EMAIL PROTECTED]:~$ java -version java version "1.6.0_07" Java(TM) SE Runtime Environment (build 1.6.0_07-b06) Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing) Any ideas? Thanks, Blaine --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Trying to get the ants demo to run on Windows
I feel really stupid - I'm pretty sure I just forgot to build. Anyhow, the ant simulation works perfectly (ubuntu, clojure revision 1131). It's real cool. Sure is alot going on with just 200 or so lines of codes. On Nov 29, 12:51 pm, Blaine <[EMAIL PROTECTED]> wrote: > Hi there, > > I'm having almost the same problem. I'm trying to get the ants demo > running in ubuntu, and I get Rob's second problem: > > user=> (def panel (doto (proxy [JPanel] [] > (paint [g] (render g))) > (.setPreferredSize (new Dimension > (* scale dim) > (* scale dim) > java.lang.IllegalArgumentException: No matching method > found: .setPreferredSize for class clojure.lang.Proxy__203 > (NO_SOURCE_FILE:7) > > The rest of the file loads - if I run clojure from within slime I can > individually compile the rest of the defns. (That said, I can no > longer start clojure from within slime. After updating clojure it > stopped working.) > > I'm at revision 1128 for clojure. > > I'm new to Java, so is it possible that I don't have some Swing/AWT > thing installed? No complaint from: > > user=> (import > '(java.awt Color Graphics Dimension) > '(java.awt.image BufferedImage) > '(javax.swing JPanel JFrame)) > nil > > And, the java version, in case that's relevant: > > [EMAIL PROTECTED]:~$ java -version > java version "1.6.0_07" > Java(TM) SE Runtime Environment (build 1.6.0_07-b06) > Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing) > > Any ideas? > > Thanks,Blaine --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---