1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
(ns clj-demos-344.core) (def x 3) (defn sequential-decl [] (let [x 5 y (+ 1 x)] (println "x:" x "y:" y))) (defn hashmaps [] (let [hmap {:key :val :key1 :val1 :key2 :val2}] (println (:key1 hmap)) (println (hmap :key1)) (println (hmap :key3) 0) (println (first hmap)) (println (rest hmap)) (println (keys hmap)) (println (vals hmap)))) (defn java-interop [] (println (.toUpperCase "csc344")) ;; Call to public method toUpperCase on String. (println (.-x (java.awt.Point. 1 2))) ;; Access the field for 'x' in a new Point object. (println (System/getProperty "java.vm.version"))) ;; Static function call. (defn map-and-reduce [] (println (map inc '(1 2 3 4 5))) (println (map list [1 2 3] '(a b c) '(4 5 6))) (println (map list [1 2 3] '(a b c) '(4 5))) (println (reduce + [1 2 3 4 5])) (let [s (str "It was the best of times, it was the worst of times, it was the age of wisdom," "it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity," "it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair,")] (println (reduce #(assoc %1 %2 (inc (%1 %2 0))) {} (re-seq #"\w+" s))))) (defn lazy-effects [x] (map #(println %) x)) (defn test-lazy [n] (take n (lazy-effects '(a b c d e f g)))) (defn inifite-seqs [n] (take n (range))) |