This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (type []) | |
clojure.lang.PersistentVector | |
user=> (type '()) | |
clojure.lang.PersistentList$EmptyList | |
user=> (type [1]) | |
clojure.lang.PersistentVector | |
user=> (type '(1)) | |
clojure.lang.PersistentList | |
user=> (= [] '()) | |
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn prime? [n] | |
(cond | |
(== 1 n) false | |
(== 2 n) true | |
(even? n) false | |
:else (->> (range 3 (inc (Math/sqrt n)) 2) | |
(filter #(zero? (rem n %))) empty?))) | |
(time (prime? 1125899906842679)) | |
; "Elapsed time: 2181.014 msecs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'x | |
;= x | |
'(+ x x) | |
;= (+ x x) | |
(list? '(+ x x)) | |
;= true | |
(list '+ 'x 'x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Literal syntax Numeric type | |
42, 0xff, 2r111, 040 long (64-bit signed integer) | |
3.14, 6.0221415e23 double (64-bit IEEE floating point decimal) | |
42N clojure.lang.BigInt (arbitrary-precision integera) | |
0.01M java.math.BigDecimal (arbitrary-precision signed floating point decimal) | |
22/7 clojure.lang.Ratio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (try (/ 1 0) true (catch Exception e false)) | |
false | |
user=> (try (/ 1 1) true (catch Exception e false)) | |
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shell:~ >: cat t.clj | |
(ns t) | |
(defn -main [& args] | |
(println "Hello world")) | |
Shell:~ >: java -cp ".:.clojure/clojure.jar" clojure.main -m t | |
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 | |
Hello world | |
Shell:~ >: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[clojure.inspector :only (inspect inspect-tree)]) | |
(inspect-tree (System/getProperties)) | |
(inspect-tree {:clojure {:creator "Rich" :runs-on-jvm true}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (for [file "ABCDEFGH" rank (range 1 9)] (format "%c%d" file rank)) | |
("A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "D1" "D2" "D3" "D4" "D5" "D6" "D7" "D8" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8") | |
user=> (for [rank (range 1 9) file "ABCDEFGH"] (format "%c%d" file rank)) | |
("A1" "B1" "C1" "D1" "E1" "F1" "G1" "H1" "A2" "B2" "C2" "D2" "E2" "F2" "G2" "H2" "A3" "B3" "C3" "D3" "E3" "F3" "G3" "H3" "A4" "B4" "C4" "D4" "E4" "F4" "G4" "H4" "A5" "B5" "C5" "D5" "E5" "F5" "G5" "H5" "A6" "B6" "C6" "D6" "E6" "F6" "G6" "H6" "A7" "B7" "C7" "D7" "E7" "F7" "G7" "H7" "A8" "B8" "C8" "D8" "E8" "F8" "G8" "H8") | |
from: http://stackoverflow.com/questions/10966142/what-is-the-difference-between-while-and-when-in-clojure | |
:when iterates over the bindings, but only evaluates the body of the loop when the condition is true. | |
:while iterates ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(declare my-odd? my-even?) | |
(defn my-odd? [n] | |
(if (= n 0) | |
false | |
#(my-even? (dec n)))) | |
(defn my-even? [n] | |
(if (= n 0) | |
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "SYSTEM Backup start at `date`!" | |
cd / | |
tar -czpf - --exclude=/proc \ | |
--exclude=/sys \ | |
--exclude=/mnt \ | |
--exclude=/media \ | |
--exclude=/dev \ |