On Aug 30, 2009, at 3:24 AM, Dan Fichter wrote:
> I'd like to convince some Python developers that Clojure is not
> foreign and does many things better than Python. I'd appreciate
> whatever suggestions you have about what I've written.
>
> Though I am crazy about STM and Clojure agents, I don't deal with
> them here. This has to be a gentle introduction rather than a
> thorough survey of Clojure, so I've left out other language
> features, too.
It's certainly a comprehensive survey of parallel impls of various
patterns. I've no idea how effective it'll be, not being a python
programmer (any more!), but it's worth a shot.
One thing did trouble me, though:
> Define a capturer object that can do two things: capture something,
> and return everything it's captured so far.
>
> [Clojure]
>
> (defn create-capturer []
> (let [captured (atom #{})]
> {:capture (fn [x] (swap! captured conj x))
> :get-all-captured (fn [] (deref captured))}))
I know you're trying to draw parallels, but I think this goes too far
in trying to write python (or java) in clojure, especially given
immutable data structures. All you need are #{x} to create a
'capturer', (conj c x) to add a new item to it, and c to get the set
of things captured so far. I know you know that, but presenting the
above doesn't seem to do anyone any favors since it's absolutely not
idiomatic.
Alternatively, if you feel like you must approach a direct corollary,
this is a little better IMO (I cringe a little at poor-man's closure-
methods :-):
(defn capture
([x] (atom #{x}))
([c x] (do
(swap! c conj x)
c)))
And of course, @c will get you the set of captured objects.
- Chas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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
-~----------~----~----~----~------~----~------~--~---