Last active
February 3, 2016 14:54
-
-
Save nali/97fbf620d48fc0fddbde to your computer and use it in GitHub Desktop.
Some basic Clojure commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Install Clojure | |
; brew install clojure | |
; Install Leiningen | |
; brew install leiningen | |
; Now, on your command line, do a | |
; lein repl | |
; from any folder to invoke an interactive environment | |
; Try out the following commands! | |
; Do a simple calculation | |
(+ 1 2) | |
(+ 1 2 3) | |
; Secret Java | |
(class "Hey") | |
(class 7) | |
; Collections | |
'(1 2 3) ; linked list | |
[1 2 3] ; extends from a Java array | |
(class '(1 2 3)) | |
(class [1 2 3]) | |
; Create a list with values 0 to n-1 | |
(range 5) | |
(take 3 (range 5)) | |
; Create a lazily evaluated list | |
(range) | |
(take 3 (range)) | |
; Assign a value | |
(def heyThere "Hey there!") | |
; Use a Java method | |
(.toUpperCase heyThere) | |
; Define a function | |
(defn helloWorld [] "Hello world") | |
; Define an overloaded function | |
(defn helloWorld2 | |
([] "Hello world") | |
([name] (str "Hello " name)) | |
) | |
; Define an atom | |
(def myAtom (atom 3)) | |
;Check the value | |
@myAtom | |
; Update the value | |
(swap! myAtom + 1) | |
; Tell me moar! | |
; The graphics library you can use to make pretty images onscreen | |
; https://github.com/quil/quil | |
; Really! Actually great Clojure documentation, with *examples*. Community built. | |
; https://clojuredocs.org/ | |
; Simple exercises to help you through understanding the language | |
; https://www.4clojure.com/ | |
; If you want to look at the typespeed game implementation | |
; https://bitbucket.org/nali/pl/src/4dc6b2e05c7f/typespeed/?at=master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment