Skip to content

Instantly share code, notes, and snippets.

@bendisposto
Created October 27, 2014 18:47
Show Gist options
  • Save bendisposto/b90fac43a24f90e31c6b to your computer and use it in GitHub Desktop.
Save bendisposto/b90fac43a24f90e31c6b to your computer and use it in GitHub Desktop.
Code aus der Vorlesung vom 23.10.2014
;; Emacs/Leiningen Integration: Cider
;; (https://github.com/clojure-emacs/cider)
;; Mein Emacs Setup:
;; https://github.com/bendisposto/emacs.d
;; Andere Editoren sind auch ganz toll!
(use 'clojure.repl)
(doc source)
(doc doc)
(source doc)
(apropos "map")
(doc pmap)
(source map)
;; ---------- Strings
"foo"
(type "foo")
"hallo
welt"
;; ---------- Characters
\f
(type \f)
(str "foo" \f)
\n
\space
(str "Hallo" "Welt")
(str "Hallo" \space "Welt")
\newline
(str "Hallo" \newline "Welt")
(println *1)
\u03bb
(println \u03bb "Kalkül" "ftw!")
;; ---------- Numbers
3
(type 3)
0x33
012
2r1011
7r666
36rCrazy
(type 36rCRAZY)
(type 9223372036854775807)
(type 9223372036854775808)
3N
(type 3N)
(inc 4)
(inc 9223372036854775807)
(+ 9223372036854775807 1)
(inc' 9223372036854775807)
(*' 9223372036854775807 9223372036854775807)
;; ---
3.141592653589793
(type 3.141592653589793)
3.141592653589793238
3.141592653589793238M
(type 3.141592653589793238M)
22/7
(type 22/7)
(/ (inc 32) 7)
(inc 32)/7 ;; geht nicht!
(/ 22 7)
(type (/ 22 7))
2/6
(type 8/2)
;; Vorsicht! Ratio kann langsam sein!
;; ---------- Names
*clojure-version*
(type *clojure-version*)
inc
+'
blah!
(quote *clojure-version*)
;; In Düsseldorf ist ein ü
(type (quote *clojure-version*))
foo
(quote foo)
(quote foo!)
(quote foo?)
(quote Foo.)
(quote .foo)
'blah!
(quote blah!)
:foo
::foo
(type :foo)
*clojure-version*
;; ---------- Regex
#"([0-9]{4})/([0-9]{2})/([0-9]{2})"
(type #"([0-9]{4})/([0-9]{2})/([0-9]{2})")
(map type '(re-matches #"([0-9]{4})/([0-9]{2})/([0-9]{2})" "2014/10/23"))
;; ---------- Kollektionen
(list 1 :zwei 3)
'(1 2 3)
(type ,,,, '(1 2 3))
[1 2 ,,,,,4,,,]
(type [str, 2, :foo, \space])
(nth [1 2 3] 2)
(conj [1 2 3] 1)
(conj '(1 2 3) 1)
(.hashCode [1 2 3])
(vector 1 2 3)
{:name "Bendisposto", :vorname "Jens" :alter :uHu}
{[1] \n [] \l }
(type {:key1 "foo", 2 9})
(assoc {:foo 1} :bar 2)
{:kaboom 1 :kaboom 2}
{:kaboom 1 :kaboom 1}
(assoc {:kaboom 1} :kaboom 2)
#{2 3 5 7 11}
(type #{str, 2, :foo, \space})
#{1 1 1}
(def n [{:name "Bendisposto", :vorname "Jens" :alter :uHu}
{:name "Witulski", :vorname "John" :alter :bivi}])
((n 1) :name)
(get-in n [1 :name])
;; ---------- Call
(+ 1 2 3)
(+ (* 3 4) 11 112)
(*)
;; ---------- apply
(+ [1 2 3])
(apply + [1 2 3])
;; ---------- Homoiconicity
(+ 1 2 3)
'(+ 1 2 3)
'(+ 1 x 3)
(map type '(+ 1 x :foo))
(list + 1 2 3)
(eval (list + 1 2 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment