ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
CLOJURE 101
@logaan
Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101
WEB
APPS
GUI
GUI
MOBILE
TERMINAL
ANIMATION
MUSIC
Girl Geek Dinners - Clojure 101
GAMES
ARDUINO
HEALTH
SPACE
Girl Geek Dinners - Clojure 101
true
false
3.14
"Kittens are cute"
nil
ram
'ram
¡®farm-animal/ram
¡®computer-part/ram
¡®demolition-tool/ram
:bug
:insect/bug
:software/bug
Girl Geek Dinners - Clojure 101
[1 2 4]3, , ,
4][1 2 3
[1 2 :three "four"]
:bar 2},{:foo 1
:bar 2}{:foo 1
{
"fizz" true
:bugs false
[1 2 3] {:do "re"}
}
#{1 2 3}
'(1 2 3)
Girl Geek Dinners - Clojure 101
print "Hello, World")(
print "Hello, World")(
(+ 40 2)
(+ 10 8 20 4)
(fn [name]
(print "Hello " name))
(def host "Zendesk")
(print "Hello " name))
fn [name](
greet(def
)
fn greet(def
(print "Hello " name))
[name]
Girl Geek Dinners - Clojure 101
(defroutes app
(GET "/" []
"<h1>Hello World</h1>")
(route/not-found
"<h1>Page not found</h1>"))
WEB
(generate-string {:foo "bar" :baz 5})
=> {¡°foo¡±: ¡°bar¡±, ¡°baz¡±: 5}
(parse-string "{"foo":"bar"}")
;; => {"foo" "bar"}
JSON
(html [:span {:class "foo"} "bar"])
=> "<span class="foo">
bar
</span>"
?
(html [:ul
(for [x (range 1 4)]
[:li x])])
=> "<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>"
HTML / XML CREATION
(def xml-doc
(parse (File. "calendar.xml")))
(get-in xml-doc [:content 1 :content 0 :content])
=> [¡°Rover¡¯s birthday¡±]
XML READING
(deftest addition-tests
(is (= 5 (+ 3 2)))
(is (= 10 (+ 5 5))))
UNITTESTING
Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101
THANKYOU
QUESTIONS?
OVERTIME
(reverse '(7 10 -))
; => (- 10 7)
(defmacro backwards [call]
(reverse call))
(- 10 7) ; => 3
MACROS
(- 10 7) ; => 3
(backwards (7 10 -)) ; => 3
(defmacro backwards [call]
(reverse call))
MACROS
def fib(0) do 0 end
def fib(1) do 1 end
def fib(n) do
fib(n-1) + fib(n-2)
end
PATTERN MATCHING
(defn-match fib
([0] 1)
([1] 1)
([?n] (+ (fib (- n 1))
(fib (- n 2)))))
for i := 0; i < 10; i++ {
go func(i int) {
sleep := time.Duration(rand.Intn(1000))
time.Sleep(sleep * time.Millisecond)
fmt.Println(i)
}(i)
}
GOROUTINES
(for [i (range 10)]
(go
(Thread/sleep (rand-int 1000))
(println i)))
Girl Geek Dinners - Clojure 101

More Related Content

Girl Geek Dinners - Clojure 101