Hi, Am 02.02.2010 um 23:48 schrieb Wardrop:
> (for [line (line-seq (reader "C:\\filedupes.txt"))] > (cond > ((complement nil?) (re-matches #"([0-9]+) byte\(null\)each:" > line)) > (println "Byte pattern!") > ((complement nil?) (re-matches #".*(\.[0-9a-zA-Z]+)" line)) > (println "File pattern!") > ) > ) > > (println "Finished!") > > The problem is, the only output I get is "Finished!". If however, I > run this on the command line, I get a long list of nil's in amongst > the strings "Byte pattern!" and "File pattern!". I expect the nil's > not to show when this is run as a script, but why are the > aforementioned strings not being output? As Kevin said: for is lazy. The println's never get evaluated because the sequence is not realised. In the repl it is (the printed nils) and hence the println's are executed. > While you're at it, you may be able to help me with an additional > problem I'm trying to tackle. As you can see if the above code, I'm > trying to match on certain lines of a text file. I'm using "cond" to > do this with as a switch statement is the only way I know how to > achieve what I'm after. Anyway, I not only want the regex to be used > in the condition expression, but also want to capture the first sub- > match (i.e. what's in the parenthesis inside the regex). What's the > best way I can do this, without having to re-run the regex twice. This might get you started: http://groups.google.com/group/clojure/msg/d9ef152e19f5416b Sincerely Meikel -- 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