Created
January 18, 2017 01:39
-
-
Save brunogs/69730c05b9f5226ace7e2fabb7910e2d to your computer and use it in GitHub Desktop.
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
Namespace | |
(ns learnclojure) | |
Types | |
(type 1) | |
(type 1.1) | |
(type true) | |
(type "Hello") | |
(type (keyword "a")) | |
(type (quote a)) | |
(type 'a) | |
(type (list 1 2 3)) | |
(type (vector 1 2 3)) | |
(nth (vector 1 2 3) 2) | |
(last (list 1 2 3)) | |
List | |
(type (list 1 2 3)) | |
(type (vector 1 2 3)) | |
Map | |
{:a 1 :b 1 :c 1} {:a 1, :b 1, :c 1} | |
(hash-map :a 1 :b 1 :c 1) | |
Set | |
{type #{1 2 3}} | |
(hash-set 1 2 3) | |
========================================================= | |
Control Flow | |
//define var with value | |
(def x "Hello") | |
(if (empty? x) | |
"x is empty" | |
"x is not empty") | |
(if (empty? x) | |
nil | |
(do | |
(println "ok") | |
:ok)) | |
(if-not (empty? x) | |
(do | |
(println "ok") | |
:ok)) | |
(when (not (empty? x)) :ok) | |
(case x | |
"Goodby": goodbye | |
"Hi": hello | |
:nothing) | |
(cond | |
(= x "Goodbye") :goodbye | |
(- (reverse x) "olleH") :olleh | |
:otherwise :nothing) | |
============================================== | |
Functions | |
(def hello (fn [] "Hello")) | |
(hello) | |
#(str "Helo) | |
(defn hello [] "Hello") | |
(defn hello [name] (str "Hello, " name)) | |
(defn hello "Greets a person named <name> with their <title>" [name, title] (str "Hello, " title " " name)) | |
(require '[clojure.repl :refer [doc]]) | |
(doc hello) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment