Skip to content

Instantly share code, notes, and snippets.

- [2] => Paper Object
- (
- [id:Paper:private] =>
- [title:Paper:private] => TestPaper
- [author:Paper:private] =>
- [authorID:Paper:private] => 0
- [lastEditor:Paper:private] =>
- [dateSubmitted:Paper:private] =>
- [lastEdited:Paper:private] =>
- [paperSynopsis:Paper:private] =>
(defn my-count [coll]
(reduce (fn [n x] (inc n)) 0 coll))
(my-count [1 2 3 3])
(defn my-reverse [coll] ;;only works for vectors atm
(reduce (fn [xs x] (into [x] xs)) [] coll))
(my-reverse [1 2 3])
(defn count-dots [s]
(count (filter #(= \. %) s)))
(defn reverse-int
"Returns an integer with its digits reversed, e.g. 123 returns 321"
[x]
(BigInteger. (su/reverse (pr-str x))))
(defn palindromic?
"Returns true if the number is palindromic, e.g. 121, 1234321"
[x]
(= x (reverse-int x)))
(->> (clojure.lang.Compiler/analyze clojure.lang.Compiler$C/EVAL
'(let [a 3 b 4] a)) .fexpr .methods first .locals keys (map #(.sym
%)))
(defmodel User
:username
:password)
(defmodel Comment
:text
[:belongs-to User])
(defmodel Post
:text
(ns clojure_refactoring.rename-fn-test
(:use clojure.test))
(deftest test-fn-location
(in-ns 'refactoring-test-fn-rename)
(clojure.core/refer-clojure)
(defn a [b] (inc b))
(in-ns 'clojure_refactoring.rename-fn-test)
(refer 'refactoring-test-fn-rename)
(is (not= (find-var 'refactoring-test-fn-rename/a)
(deftest test-fn-location
(create-ns 'refactoring-test-fn-rename)
(with-ns 'refactoring-test-fn-rename
(clojure.core/refer-clojure)
(defn ^{:line 19 :file "foo.clj"} a [b] (inc b)))
(is (= (:line (meta (find-var 'refactoring-test-fn-rename/a)))
19))
(remove-ns 'refactoring-test-fn-rename))
(deftest test-fn-location
(create-ns 'refactoring-test-fn-rename)
(with-ns 'refactoring-test-fn-rename
(clojure.core/refer-clojure)
(defn a [b] (inc b)))
(is (= (:line (meta (find-var 'refactoring-test-fn-rename/a)))
19))
(remove-ns 'refactoring-test-fn-rename))
BartJ:
I have read chapter 1 (which is freely available) and I can tell you that, I think this is *THE* book to learn Clojure if you are a programmer.
What I love about the book?
1. Clarity of explanation
2. Conversant style
3. Very coherent, succinct and to the point examples.