82 lines
1.5 KiB
Plaintext
82 lines
1.5 KiB
Plaintext
|
(ns hello-world.core
|
||
|
(:require [om.core :as om :include-macros true]
|
||
|
[om.dom :as dom :include-macros true]))
|
||
|
|
||
|
(enable-console-print!)
|
||
|
|
||
|
(println "This text is printed from src/hello-world/core.cljs. Go ahead and edit it and see reloading in action.")
|
||
|
|
||
|
;; define your app data so that it doesn't get over-written on reload
|
||
|
|
||
|
(defonce app-state (atom {:text "Hello world!"}))
|
||
|
|
||
|
|
||
|
(om/root
|
||
|
(fn [data owner]
|
||
|
(reify om/IRender
|
||
|
(render [_]
|
||
|
(dom/div nil
|
||
|
(dom/h1 nil (:text data))
|
||
|
(dom/h3 nil "Edit this and wtc it change!")))))
|
||
|
app-state
|
||
|
{:target (. js/document (getElementById "app"))})
|
||
|
|
||
|
(defn on-js-reload []
|
||
|
;; optionally touch your app-state to force rerendering depending on
|
||
|
;; your application
|
||
|
;; (swap! app-state update-in [:__figwheel_counter] inc)
|
||
|
)
|
||
|
|
||
|
(.getElementById js/document "app")
|
||
|
|
||
|
|
||
|
(defn average [a b]
|
||
|
(/ (+ a b) 2.0)) ;; blah
|
||
|
|
||
|
(average 3 8)
|
||
|
|
||
|
|
||
|
(loop [[n & numbers] '(1 2 3 4 5)
|
||
|
result '()]
|
||
|
(let [result (cons (* n n) result)]
|
||
|
(if numbers
|
||
|
(recur numbers result)
|
||
|
result)))
|
||
|
|
||
|
(loop [x 10]
|
||
|
(let [result x]
|
||
|
(when (> x 1)
|
||
|
(println x)
|
||
|
(recur (- x 2)))
|
||
|
))
|
||
|
|
||
|
(defn head [[n & _]]
|
||
|
(println (+ n 1))
|
||
|
n)
|
||
|
|
||
|
(head '(3 2 1))
|
||
|
|
||
|
(even? 4)
|
||
|
|
||
|
(declare ^{:dynamic true} *foo*)
|
||
|
|
||
|
(def l '(1 2 3))
|
||
|
|
||
|
(defn with-foo [f]
|
||
|
(binding [*foo* "I exist!"]
|
||
|
(f)))
|
||
|
|
||
|
; ; (with-foo #(println *foo*)) =>"I exist!"
|
||
|
|
||
|
|
||
|
(str "Hello" " " "World")
|
||
|
|
||
|
;; functions
|
||
|
|
||
|
((fn add-five [x] (+ x 5)) 6)
|
||
|
((fn [x] (+ x 5)) 3)
|
||
|
(#(+ % 5) 3)
|
||
|
((partial + 5) 3)
|
||
|
|
||
|
; (add-five 3)
|