Fork me on GitHub

Ahh, finally figured out what was eating all the newlines in my <pre> tags in the XML blog files that I'm importing. Turns out that doesn't just return the content of the node, it does whitespace removal as well.


I'm puzzled: does anybody really want the current behavior where it replaces the regexp of (str "[\\s" (char 160) "]+") with a single space?


is it possible to create a defmethod that will match on any value for a given argument?


:default isn't really what I want, I thin


actually, it might be


anyone have a strong understanding of Perlin noise and want to help me with my clojure implementation of it? simple_smile happy to pay for your time if that shot in the dark came anywhere near you


Say I have two collections, and I want to compare the first to the first, second to the second, etc. Like so:

(let [f = ; but it could be anything!
      exemplars [1 2 3 4]
      candidates [1 2 3 4]]
  (for [[e c] (map vector exemplars candidates)]
    (f e c)))
Is there a nicer way? Bear in mind that I want to be able to run any function on the pairs, so the many ways of testing deep equality are out of bounds.


@jeremyraines: Do you need a Clojure implementation of Perlin noise, or are you specifically trying to get your version working? If it's important enough that you're willing to pay, then the former might be true...


And in either case, there are a few existing implementations in Clojure that might steer you the right way.


it's the latter, for understanding. I'm willing to pay just because I'm frustrated


The closest I ever came to Perlin noise was watching Ken Perlin give a talk on it, which was fascinating, but light on technical details. Sorry I can't help personally.


on your question: is f a comparator so what you want back is a collection of trues and falses?


look at every? but you seem on the rigt track


Yeah, I could do the same thing with (every? (fn [[e c]] (f e c)) (map vector exemplars candidates)), and it might be a bit more intention-revealing.


In my specific case, exemplars is a collection of maps, where I expect the candidates to have the values from the exemplar maps, but possibly additional ones. To be exact, I'm just testing database stuff, where I don't care about the timestamps and whatnot. It's not exactly rocket science, but anything I learn while doing basic stuff can only help me when doing more complicated stuff.


In particular, doing the (map vector coll1 coll2) thing to get a pairwise collection feels like a roundabout way of doing something simple.


(partition 2 (interleave coll1 coll2)) is very similar, and more self-documenting, I guess. map vector, I have no idea how that even works.


I mean, I vaguely remember that (map f coll1) runs (f element) on each element, and (map f coll1 coll2) runs (f element1 element2), so that's how it works, but it's tricky.


(map vector c1 c2) works because map takes a variable number of collections, yeah


Just thinking aloud.


that version with every? seems good. I could be wrong but I think it has the benefit of being lazy, too, where the for version isn't


True, since partition and interleave both return lazy seqs if possible, also.


@amacdougall: Does (map = exemplars candidates) not work?


oh - thanks! not sure why I had that misunderstanding


If you wanted to get to the first false comparison you could do (first (filter false? (map = exemplars candidates)))


Probably thinking of doseq simple_smile


Is there something that looks vaguely like the opposite of interleave? Something that takes coll, n, and returns an n-element collection of collections? E.g., (foo 3 [1 2 3 4 5 6]) ;; => ((1 4) (2 5) (3 6))


ahh partition


jeez, shoulda scrolled up


Though, that partitions by number of elements, not number of resulting collections


(defn foo [n coll]
  (let [size (/ (count coll) n)]
    (partition size coll)))


although you'd have to handle sizes that aren't cleanly divisible


@jeremyraines: apparently my question was asked an answered in 2009 (!topic/clojure/f31RdxAbwZI)

(defn unravel [n coll] 
  (map #(take-nth n (drop % coll)) (range n))) 


nice. Love seeing Chouser's always-more-concise solutions after I finish a 4clojure problem simple_smile