On Github bodil / more-than-functions
class EvenJavaCanMap {
interface Fn<T> {
T apply(T value);
}
public static List<T> map(Fn<T> fn, List<T> list) {
List<T> newList = new LinkedList<T>();
for (T item : list)
newList.add(fn.apply(item));
return newList;
}
}
fib 0 = 0 fib 1 = 1 fib n = fib (n - 1) + fib (n - 2)
(defn fib [n]
(if (< n 2) n
(+ (fib (- n 1))
(fib (- n 2)))))(def primes [2 3 5 7 11 13]) (assoc primes 3 42)
(cons 5 nil) (cons 4 (cons 5 nil)) (cons 3 (cons 4 (cons 5 nil)))
;; This is a function call: (max 4 5 6) ;; This is a list: '(max 4 5 6)
(defn invoke-func [name arg] `(~(symbol name) ~arg))
(use 'hiccup.core) (html [:body [:h1#title "Hello"] [:p.article "Hello world!"]])
(use 'korma.core)
(defentity person)
(dry-run
(select person
(where {:name "Bodil" :age [> 18]})
(order :name :ASC))); Maps
(def pony-types
{"Pinkie Pie" "Earth pony",
"Rainbow Dash" "Pegasus pony",
"Rarity" "Unicorn pony"})
; Sequences
(def ponies
["Pinkie Pie" "Applejack" "Rainbow Dash"
"Rarity" "Fluttershy" "Twilight Sparkle"])(def ponies-as-string (str ponies)) ((read-string ponies-as-string) 2)
(def counter-state (atom 0)) (defn count-up [] (swap! counter-state inc) @counter-state)
(defn sum-to [n] (reduce + (range n))) ; (sum-to 250000000)