Skip to content

Instantly share code, notes, and snippets.

@brunogs
Created January 18, 2017 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunogs/69730c05b9f5226ace7e2fabb7910e2d to your computer and use it in GitHub Desktop.
Save brunogs/69730c05b9f5226ace7e2fabb7910e2d to your computer and use it in GitHub Desktop.
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