Hmmm... I think you're confusing the issue. Your compliant seems to be more directed at "magic numbers" than regexes. If I understand your argument (which I agree with):
;bad code (filter #"\d+" maybe-numbers) ;good code (let [is-number-regex #"\d+"] (filter is-number-regex maybe-numbers)) Granted, some understanding of regexes is required. However, if you're hacking Lisp, I think you've moved beyond beginner status, and expecting a basic familiarity of a regex is fair. My $.02 Sean On Aug 27, 1:37 pm, eyeris <drewpvo...@gmail.com> wrote: > I have the same urge, to want to use regexps as predicates. However I > definitely would not like to read such code. I can only imagine having > to try to read such code if I didn't understand regexps. E.g. (filter > #"\d+" maybe-numbers) is clear enough to someone who understands > regexps. However (filter is-number-regex maybe-numbers) is clear to > even programmers that don't understand regexps. > > On Aug 27, 10:41 am, Sean Devlin <francoisdev...@gmail.com> wrote: > > > On Aug 27, 1:06 am, Timothy Pratley <timothyprat...@gmail.com> wrote: > > > > > Granted, this wouldn't work for anything that gets passed to Java, but > > > > the following gist would be a start. > > > >http://gist.github.com/176032 > > > > You already have a getPattern method for those cases. Which suggests > > > another solution: > > > > (defn re-fn > > > "Uses ss to construct a java.util.Pattern. > > > Returns a function which returns the Pattern if called with no > > > arguments, > > > and calls re-seq if called with a string argument." > > > [ss] > > > (let [pp (re-pattern ss)] > > > (fn re > > > ([] pp) > > > ([s] (re-seq pp s))))) > > > > user=> ((re-fn "2.") "12324251") > > > ("23" "24" "25") > > > user=> ((re-fn "2.")) > > > #"2." > > > > If #"X" created a (re-fn "X") then all the re functions could accept > > > a function and call it in order to avoid having to do (re-find (pp) > > > s). The previous signature could be retained so that they would work > > > with either type of arguments if that were desirable. The downside is > > > trying to explain that in the docs might be confusing - so a wrapper > > > seems more obvious for that. > > > > Oh - it seems like re-seq does the most work so perhaps that is the > > > best candidate? > > > The only feature I want is the ability to use a regex as a predicate. > > So, I'd prefer something like re-matches. Maybe this isn't the > > biggest use case, though. > > > Sean > > > > Regards, > > > Tim. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---