Hi,

Am 13.07.2010 um 14:26 schrieb j-g-faustus:

>>> I made my own cheat sheet for private use over the past month or so,
>>> core functions only. It's at the 80% stage, I don't expect it will
>>> ever be 100%, but I have found it useful:
>>> http://faustus.webatu.com/clj-quick-ref.html

Some comments after quickly skimming through:

next vs. rest: neither of those two „more“ idiomatic. They are just different. 
next will realise the next element of the sequence (of any), while rest will 
not. So in general you want rest, but sometimes next is useful, eg. in a loop: 
(loop [s (seq s)] (when s (do-something) (recur (next s))).

Your comment on sequence is wrong: sequence and seq are – like rest and next – 
two different things. It's not that sequence was the „old“ seq.

replicate is a relic from the time where repeat didn't have an optional n.

Your examples on transients are wrong. You have to capture the return value of 
the bang! functions as you would do with the non-bang versions. That 
(persistent! tm) works in your examples is an implementation detail.

condp has another form, which could be mentioned because it is not widely known:

user=> (condp some [1 2 3]
         #{2 4 6} :>> inc
         #{3 5 7} :>> dec)
3

recur recurs not only to the function, but also to the same arity. So (fn ([a] 
(println a)) ([a b] (recur (+ a b)))) does not work.

extends? does check whether (extend ...) was called on a protocol with the 
given type. This can be a Java class or something defined with with 
deftype/defrecord. However for the latter not when the protocol methods where 
specified inline.

io! is inside the transaction, but can be defined outside. (defn fn-with-io [] 
(io! (do-stuff))) ..... (dosync (fn-with-io)) <- exception

You might want to mention #_ in the comments section. It is a reader macro 
which drops the following read thing. Useful to comment out code without 
messing with the parens.

user=> [1 2 #_ 3]
[1 2]

In the require example: specifying :reload in an ns declaration smells.

You can also use :as with :use. (ns foo.bar (:use [frob.nicator :only 
(defflogistionreactor) :as frobber])). Can be useful at times.

I don't like your use of '(quote lists) everywhere. Please use vectors. They 
are the idiomatic answer of Clojure to quoted lists. Use quoted lists only 
where it is interesting to distinguish the list from the vector, eg. in (vec 
'(1 2 3)). (Related: if you find yourself quoting symbols, this means you 
should use backquote because your are writing a macro or you should actually 
use keywords.)

I really like your examples! They are simple, easy to understand, demonstrate 
edge cases and focus on the thing being demonstrated. Two thumbs up.

Hope that helps.

Sincerely
Meikel

PS: I'm apologise if some this seems to be nit-picking.

-- 
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

Reply via email to