Thanks Sean, this was a great exercise. I'm comfortable reading
Clojure code, but writing it requires thinking differently from what I
am used to. My solution is clunky and less elegant than most of the
other submissions in this thread, but I avoided reading any of them
until I had implemented the
ok, great ! :-)
2010/1/25 Sean Devlin :
> Laurent,
> This thread is a set up. Specifically, I'm hoping these guys pick up
> the blog post:
>
> http://www.katacasts.com/
>
> I plan on posting a video in about a week going through everything.
> Demonstrate the power of the sequence abstraction, and
Laurent,
This thread is a set up. Specifically, I'm hoping these guys pick up
the blog post:
http://www.katacasts.com/
I plan on posting a video in about a week going through everything.
Demonstrate the power of the sequence abstraction, and the
similarities of regexs and predicates. Show how C
Hello,
So far, i've encountered the term of "kata" applied to software in a
somewhat similar sense as in the martial arts: very detailed
step-by-step explanation of how one things about the problem, solves
it bit by bit (does he first play with some functions at the REPL,
does he start to code fro
Hi Group,
thought this nice puzzle would make a good occasion for a first
post. :-)
A solution to the original problem from c.l.s, with keywords replacing
symbols:
(ns sogaard-kata
(:use clojure.contrib.seq-utils))
(defn sogaard-kata [xs]
(map (fn [[k ys]] (into (vec k) (vec ys)))
(p
Golf! Yeah!
Here the low-level version:
(defn sift
[pred coll]
(letfn [(step
[sep [f :as s] xs]
(if (or (not s) (pred f))
(cons [sep xs] (sift pred s))
(recur sep (next s) (conj xs f]
(lazy-seq
(when-let [s (seq coll)]
Here a different version, without the sequence abstraction. I realise
its idiomatically obsolete, but thought you guys might enjoy it.
(defn sift
"Sift. Old Skool."
[key-pred in-s]
(reduce
(fn [coll elem]
(if (key-pred elem)
(conj coll [(str elem) []])
(conj
(po
Hi Patrick,
On Sun, Jan 24, 2010 at 9:58 PM, CuppoJava wrote:
> It's an elegant puzzle. Thanks Sean!
>
> Here's my take:
> (defn sift [pred? s]
> (lazy-seq
> (if (seq s)
> (let [key (first s)
> [vals remaining] (split-with #(not (pred? %)) (rest s))]
> (cons [key vals]
That's very thoughtful Travis. I was also considering generalizing
regular expressions to apply to arbitrary ordered collections for this
question. That is the most elegant abstraction for this problem. I
suppose there just isn't enough real-world use for a regex on
collections to justify the effor
Occasionally things like this remind me of the similarities between
parsing character sequences and dealing with unpredictably ordered
collections. For character sequences, the regular expression mechanism
has been invented. I wonder if any one else has ever wished for the
ability to write a regula
It's an elegant puzzle. Thanks Sean!
Here's my take:
(defn sift [pred? s]
(lazy-seq
(if (seq s)
(let [key (first s)
[vals remaining] (split-with #(not (pred? %)) (rest s))]
(cons [key vals] (sift pred? remaining))
Running:
(sift string? ["a" 2 "b" 3 4 "c" "d" 4
11 matches
Mail list logo