SlideShare a Scribd company logo
Full	
  Stack	
  Clojure	
  
Michiel	
  Borkent	
  	
  
@borkdude	
  
HAN	
  University	
  of	
  Applied	
  Sciences	
  
October	
  1st	
  2015	
  
Agenda	
  
●  Part	
  1:	
  Why	
  Clojure	
  
●  Part	
  2:	
  Some	
  basic	
  Clojure	
  
●  Part	
  3:	
  Full	
  stack	
  Clojure	
  
Part	
  1:	
  Why	
  Clojure	
  
Clojure	
  
•  Designed	
  by	
  Rich	
  Hickey	
  in	
  2007	
  
•  FrustraNon	
  with	
  Java,	
  C++	
  
•  Deliver	
  the	
  same	
  funcNonality	
  faster	
  
•  Without	
  giving	
  up	
  operaNonal	
  requirements	
  	
  
Non-­‐goals	
  
•  Easy	
  to	
  learn	
  by	
  Java	
  etc.	
  developers	
  
•  Experiment	
  in	
  language	
  design	
  
Programs	
  are	
  (mostly)	
  about	
  data	
  
•  Language	
  should	
  not	
  get	
  in	
  the	
  way	
  of	
  data	
  
•  Good	
  support	
  for	
  data	
  literals	
  
•  Data	
  transformaNons	
  
•  Data	
  is	
  immutable	
  
•  OO	
  is	
  not	
  great	
  for	
  working	
  with	
  data	
  
•  Big	
  part	
  of	
  program	
  can	
  be	
  built	
  using	
  plain	
  data	
  
	
  
Systems	
  and	
  immutability	
  
•  Each	
  system	
  receives	
  a	
  message	
  
and/or	
  sends	
  a	
  message	
  
•  MutaNng	
  a	
  message	
  does	
  not	
  
affect	
  other	
  system	
  
•  In	
  Java,	
  references	
  lead	
  to	
  
uncontrolled	
  mutaNon	
  
•  You	
  can	
  protect	
  yourself	
  by	
  using	
  
Value	
  Objects	
  or	
  DTOs,	
  but	
  takes	
  
work	
  
•  Clojure	
  adopts	
  system	
  model	
  
in	
  the	
  small	
  by	
  using	
  
immutable	
  data	
  structures	
  
•  MutaNon	
  only	
  happens	
  in	
  
controlled	
  and	
  explicit	
  ways	
  
Clojure	
  
•  dynamic	
  language	
  
•  lisp	
  
•  funcNonal	
  programming	
  
•  immutable	
  data	
  structures	
  
•  strong	
  concurrency	
  support	
  
•  embraces	
  host	
  pla_orm	
  (JVM,	
  js)	
  
•  EDN	
  
Choosing	
  a	
  language	
  is	
  all	
  about	
  trade	
  offs!	
  
	
  
Clojure	
  in	
  industry	
  
hcps://www.youtube.com/watch?v=av9Xi6CNqq4	
  
	
  
http://dev.clojure.org/display/community/Clojure+Success+Stories
http://clojure.org/Companies
Part	
  2:	
  Basic	
  Clojure	
  
Data	
  literals	
  
Keyword:	
  	
  	
  	
  	
  :a	
  
Vector:	
  	
  	
  	
  	
  [1	
  2	
  3	
  4]	
  
Hash	
  map:	
  	
  	
  {:a	
  1,	
  :b	
  2}	
  
Set:	
  	
  	
  	
  	
  	
  	
  	
  #{1	
  2	
  3	
  4}	
  
List:	
  	
  	
  	
  	
  	
  	
  '(1	
  2	
  3	
  4)	
  
Extensible	
  Data	
  NotaFon	
  
{:key1"Bar"	
  
	
  :key2	
  [1	
  2	
  3]	
  
	
  "key3",	
  #{1.0	
  2.0	
  c}	
  
	
  :key4,{:foo	
  {:bar	
  {:baz	
  'hello}}}}	
  	
  
	
  
(pr-­‐str	
  {:foo	
  "bar"})	
  
(read-­‐string	
  "{:foo	
  "bar"}")	
  
	
  
f(x)	
  -­‐>	
  (f	
  x)	
  
	
  
Syntax	
  
Syntax	
  
if	
  (...)	
  {	
  
	
  	
  ...	
  
}	
  else	
  {	
  	
  	
  	
  	
  	
  	
  -­‐>	
  
	
  	
  ...	
  	
  
}	
  
	
  
(if	
  ...	
  
	
  	
  	
  	
  ...	
  
	
  	
  	
  	
  ...)	
  
Syntax	
  
var	
  foo	
  =	
  "bar";	
  	
  
	
  
(def	
  foo	
  "bar")	
  
JavaScript	
  -­‐	
  ClojureScript	
  
if	
  (bugs.length	
  >	
  0)	
  {	
  
	
  	
  return	
  'Not	
  ready	
  for	
  release';	
  
}	
  else	
  {	
  
	
  	
  return	
  'Ready	
  for	
  release';	
  
}	
  
	
  
(if	
  (pos?	
  (count	
  bugs))	
  
	
  	
  "Not	
  ready	
  for	
  release"	
  
	
  	
  "Ready	
  for	
  release")	
  
source:	
  hcp://himera.herokuapp.com/synonym.html	
  
JavaScript	
  -­‐	
  ClojureScript	
  
var	
  foo	
  =	
  {bar:	
  "baz"};	
  
foo.bar	
  =	
  "baz";	
  
foo["abc"]	
  =	
  17;	
  
	
  
alert('foo')	
  
new	
  Date().getTime()	
  
new	
  
Date().getTime().toString()	
  
	
  
	
  
(def	
  foo	
  (js-­‐obj	
  "bar"	
  "baz"))	
  
(set!	
  (.-­‐bar	
  foo)	
  "baz")	
  
(aset	
  foo	
  "abc"	
  17)	
  
	
  
(js/alert	
  "foo")	
  
(.getTime	
  (js/Date.))	
  
(..	
  (js/Date.)	
  (getTime)	
  
(toString))	
  
source:	
  hcp://himera.herokuapp.com/synonym.html	
  
Persistent	
  data	
  structures	
  
(def	
  v	
  [1	
  2	
  3])	
  
(conj	
  v	
  4)	
  ;;	
  =>	
  [1	
  2	
  3	
  4]	
  
(get	
  v	
  0)	
  ;;	
  =>	
  1	
  
(v	
  0)	
  ;;	
  =>	
  1	
  
	
  
source:	
  hcp://hypirion.com/musings/understanding-­‐persistent-­‐vector-­‐pt-­‐1	
  	
  
Persistent	
  data	
  structures	
  
(def	
  m	
  {:foo	
  1	
  :bar	
  2})	
  
(assoc	
  m	
  :foo	
  2)	
  ;;	
  =>	
  {:foo	
  2	
  :bar	
  2}	
  
(get	
  m	
  :foo)	
  ;;=>	
  1	
  
(m	
  :foo)	
  ;;=>	
  1	
  
(:foo	
  m)	
  ;;=>	
  1	
  
(dissoc	
  m	
  :foo)	
  ;;=>	
  {:bar	
  2}	
  
FuncFonal	
  programming	
  
(def	
  r	
  (-­‐>>	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  (range	
  10)	
  	
  	
  	
  ;;	
  (0	
  1	
  2	
  ..	
  9)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  (filter	
  odd?)	
  ;;	
  (1	
  3	
  5	
  7	
  9)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  (map	
  inc)))	
  	
  	
  ;;	
  (2	
  4	
  6	
  8	
  10)	
  	
  
;;	
  r	
  is	
  (2	
  4	
  6	
  8	
  10)	
  
	
  
FuncFonal	
  programming	
  
;;	
  r	
  is	
  (2	
  4	
  6	
  8	
  10)	
  
(reduce	
  +	
  r)	
  	
  
;;	
  =>	
  30	
  
(reductions	
  +	
  r)	
  
;;	
  =>	
  (2	
  6	
  12	
  20	
  30)	
  
	
  
	
  
	
  
var	
  sum	
  =	
  _.reduce(r,	
  function(memo,	
  num){	
  return	
  memo	
  +	
  num;	
  });	
  
Sequence	
  abstracFon	
  
Data	
  structures	
  as	
  seqs	
  
(first	
  [1	
  2	
  3])	
  ;;=>	
  1	
  
(rest	
  [1	
  2	
  3])	
  ;;=>	
  (2	
  3)	
  
General	
  seq	
  funcNons:	
  map,	
  reduce,	
  filter,	
  ...	
  
(distinct	
  [1	
  1	
  2	
  3])	
  ;;=>	
  (1	
  2	
  3)	
  
(take	
  2	
  (range	
  10))	
  ;;=>	
  (0	
  1)	
  
	
  
See	
  hcp://clojure.org/cheatsheet	
  for	
  more	
  	
  
Sequence	
  abstracFon	
  
Most	
  seq	
  funcNons	
  return	
  lazy	
  sequences:	
  
	
  
(take	
  2	
  (map	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (fn	
  [n]	
  (js/alert	
  n)	
  n)	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (range)))	
  
	
   infinite	
  lazy	
  sequence	
  of	
  numbers	
  
side	
  effect	
  
Mutable	
  state:	
  atoms	
  
(def	
  my-­‐atom	
  (atom	
  0))	
  
@my-­‐atom	
  ;;	
  0	
  
(reset!	
  my-­‐atom	
  1)	
  
(reset!	
  my-­‐atom	
  (inc	
  @my-­‐atom))	
  ;;	
  bad	
  idiom	
  
(swap!	
  my-­‐atom	
  (fn	
  [old-­‐value]	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (inc	
  old-­‐value)))	
  
(swap!	
  my-­‐atom	
  inc)	
  ;;	
  same	
  
@my-­‐atom	
  ;;	
  4	
  
	
  
Lisp:	
  macros	
  
(map	
  inc	
  	
  
	
  	
  (filter	
  odd?	
  	
  
	
  	
  	
  	
  (range	
  10)))	
  
	
  
(-­‐>>	
  	
  
	
  	
  (range	
  10)	
  
	
  	
  (filter	
  odd?)	
  
	
  	
  (map	
  inc))	
  
thread	
  last	
  macro	
  
Lisp:	
  macros	
  
(macroexpand	
  	
  
	
  	
  '(-­‐>>	
  (range	
  10)	
  (filter	
  odd?)))	
  
	
  
;;	
  =>	
  (filter	
  odd?	
  (range	
  10))	
  
	
  
(macroexpand	
  	
  
	
  	
  '(-­‐>>	
  (range	
  10)	
  (filter	
  odd?)	
  (map	
  inc)))	
  
	
  
;;	
  =>	
  (map	
  inc	
  (filter	
  odd?	
  (range	
  10)))	
  
	
  
Lisp:	
  macros	
  
JVM	
  Clojure:	
  
	
  
(defmacro	
  defonce	
  [x	
  init]	
  
	
  `(when-­‐not	
  (exists?	
  ~x)	
  
	
  	
  	
  	
  (def	
  ~x	
  ~init)))	
  
	
  
	
  
ClojureScript:	
  
	
  
(defonce	
  foo	
  1)	
  
(defonce	
  foo	
  2)	
  ;;	
  no	
  effect	
  
notes:	
  	
  
●  macros	
  must	
  be	
  wricen	
  in	
  JVM	
  Clojure	
  
●  are	
  expanded	
  at	
  compile	
  Nme	
  
●  generated	
  code	
  gets	
  executes	
  in	
  ClojureScript	
  
Part	
  3:	
  Full	
  Stack	
  Clojure	
  
Full	
  Stack	
  Clojure 	
  	
  
Front-end (js)
ClojureScript
reagent + react
secretary
cljs-http
figwheel
REPL
leiningen
core.async
Prismatic/Schema
timbre
Server side (JVM)
Clojure
ring
compojure
liberator
environ
hiccup
Framework: Pedestal
Persistence RDBMS (via JDBC, e.g. PostgresQL, MySQL, H2, etc)
clojure.java.jdbc
YesQL
Datomic
Show	
  me	
  the	
  code!	
  
https://github.com/borkdude/full-stack-clojure-han-okt-2015
Get	
  started	
  with	
  Clojure(Script)	
  
•  Read	
  a	
  Clojure(Script)	
  book	
  
•  Do	
  the	
  4clojure	
  exercises	
  
•  Start	
  hacking	
  on	
  your	
  own	
  project	
  
•  Pick	
  an	
  online	
  Clojure	
  course 	
  	
  
•  Join	
  the	
  AMSCLJ	
  meetup	
  
•  Join	
  the	
  Slack	
  community	
  
	
  

More Related Content

What's hot

Clojure made really really simple
Clojure made really really simpleClojure made really really simple
Clojure made really really simple
John Stevenson
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
Mahmoud Samir Fayed
 
Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++
Sergey Platonov
 
When RegEx is not enough
When RegEx is not enoughWhen RegEx is not enough
When RegEx is not enough
Nati Cohen
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
John Stevenson
 
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Gor Nishanov,  C++ Coroutines – a negative overhead abstractionGor Nishanov,  C++ Coroutines – a negative overhead abstraction
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Sergey Platonov
 
scala-gopher: async implementation of CSP for scala
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scala
Ruslan Shevchenko
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash Features
Nati Cohen
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by example
YunWon Jeong
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in PracticeCluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
Steffen Wenz
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Csp scala wixmeetup2016
Csp scala wixmeetup2016Csp scala wixmeetup2016
Csp scala wixmeetup2016
Ruslan Shevchenko
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
Alan Uthoff
 
Minion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejsMinion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejs
Marcelo Gornstein
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
thnetos
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
Moriyoshi Koizumi
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
Steffen Wenz
 

What's hot (20)

Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Clojure made really really simple
Clojure made really really simpleClojure made really really simple
Clojure made really really simple
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
 
Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++
 
When RegEx is not enough
When RegEx is not enoughWhen RegEx is not enough
When RegEx is not enough
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
 
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Gor Nishanov,  C++ Coroutines – a negative overhead abstractionGor Nishanov,  C++ Coroutines – a negative overhead abstraction
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
 
scala-gopher: async implementation of CSP for scala
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scala
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash Features
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by example
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in PracticeCluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Csp scala wixmeetup2016
Csp scala wixmeetup2016Csp scala wixmeetup2016
Csp scala wixmeetup2016
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
 
Minion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejsMinion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejs
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
 

Similar to Full Stack Clojure

Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
Baishampayan Ghose
 
Modern technologies in data science
Modern technologies in data science Modern technologies in data science
Modern technologies in data science
Chucheng Hsieh
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
John Stevenson
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
sunng87
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France
David Delabassee
 
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
confluent
 
The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)
jaxLondonConference
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
Jacek Laskowski
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)
Phil Calçado
 
Java
JavaJava
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
Functional Thursday
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議dico_leque
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Anne Nicolas
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernel
Vitaly Nikolenko
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
Albert Bifet
 
Big data shim
Big data shimBig data shim
Big data shim
tistrue
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
Paul Lam
 

Similar to Full Stack Clojure (20)

Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Modern technologies in data science
Modern technologies in data science Modern technologies in data science
Modern technologies in data science
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France
 
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
 
The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)
 
Java
JavaJava
Java
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernel
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Big data shim
Big data shimBig data shim
Big data shim
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
 

Recently uploaded

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 

Recently uploaded (20)

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 

Full Stack Clojure

  • 1. Full  Stack  Clojure   Michiel  Borkent     @borkdude   HAN  University  of  Applied  Sciences   October  1st  2015  
  • 2. Agenda   ●  Part  1:  Why  Clojure   ●  Part  2:  Some  basic  Clojure   ●  Part  3:  Full  stack  Clojure  
  • 3. Part  1:  Why  Clojure  
  • 4. Clojure   •  Designed  by  Rich  Hickey  in  2007   •  FrustraNon  with  Java,  C++   •  Deliver  the  same  funcNonality  faster   •  Without  giving  up  operaNonal  requirements    
  • 5. Non-­‐goals   •  Easy  to  learn  by  Java  etc.  developers   •  Experiment  in  language  design  
  • 6. Programs  are  (mostly)  about  data   •  Language  should  not  get  in  the  way  of  data   •  Good  support  for  data  literals   •  Data  transformaNons   •  Data  is  immutable   •  OO  is  not  great  for  working  with  data   •  Big  part  of  program  can  be  built  using  plain  data    
  • 7. Systems  and  immutability   •  Each  system  receives  a  message   and/or  sends  a  message   •  MutaNng  a  message  does  not   affect  other  system   •  In  Java,  references  lead  to   uncontrolled  mutaNon   •  You  can  protect  yourself  by  using   Value  Objects  or  DTOs,  but  takes   work   •  Clojure  adopts  system  model   in  the  small  by  using   immutable  data  structures   •  MutaNon  only  happens  in   controlled  and  explicit  ways  
  • 8. Clojure   •  dynamic  language   •  lisp   •  funcNonal  programming   •  immutable  data  structures   •  strong  concurrency  support   •  embraces  host  pla_orm  (JVM,  js)   •  EDN  
  • 9. Choosing  a  language  is  all  about  trade  offs!    
  • 10. Clojure  in  industry   hcps://www.youtube.com/watch?v=av9Xi6CNqq4     http://dev.clojure.org/display/community/Clojure+Success+Stories http://clojure.org/Companies
  • 11. Part  2:  Basic  Clojure  
  • 12. Data  literals   Keyword:          :a   Vector:          [1  2  3  4]   Hash  map:      {:a  1,  :b  2}   Set:                #{1  2  3  4}   List:              '(1  2  3  4)  
  • 13. Extensible  Data  NotaFon   {:key1"Bar"    :key2  [1  2  3]    "key3",  #{1.0  2.0  c}    :key4,{:foo  {:bar  {:baz  'hello}}}}       (pr-­‐str  {:foo  "bar"})   (read-­‐string  "{:foo  "bar"}")    
  • 14. f(x)  -­‐>  (f  x)     Syntax  
  • 15. Syntax   if  (...)  {      ...   }  else  {              -­‐>      ...     }     (if  ...          ...          ...)  
  • 16. Syntax   var  foo  =  "bar";       (def  foo  "bar")  
  • 17. JavaScript  -­‐  ClojureScript   if  (bugs.length  >  0)  {      return  'Not  ready  for  release';   }  else  {      return  'Ready  for  release';   }     (if  (pos?  (count  bugs))      "Not  ready  for  release"      "Ready  for  release")   source:  hcp://himera.herokuapp.com/synonym.html  
  • 18. JavaScript  -­‐  ClojureScript   var  foo  =  {bar:  "baz"};   foo.bar  =  "baz";   foo["abc"]  =  17;     alert('foo')   new  Date().getTime()   new   Date().getTime().toString()       (def  foo  (js-­‐obj  "bar"  "baz"))   (set!  (.-­‐bar  foo)  "baz")   (aset  foo  "abc"  17)     (js/alert  "foo")   (.getTime  (js/Date.))   (..  (js/Date.)  (getTime)   (toString))   source:  hcp://himera.herokuapp.com/synonym.html  
  • 19. Persistent  data  structures   (def  v  [1  2  3])   (conj  v  4)  ;;  =>  [1  2  3  4]   (get  v  0)  ;;  =>  1   (v  0)  ;;  =>  1    
  • 21. Persistent  data  structures   (def  m  {:foo  1  :bar  2})   (assoc  m  :foo  2)  ;;  =>  {:foo  2  :bar  2}   (get  m  :foo)  ;;=>  1   (m  :foo)  ;;=>  1   (:foo  m)  ;;=>  1   (dissoc  m  :foo)  ;;=>  {:bar  2}  
  • 22. FuncFonal  programming   (def  r  (-­‐>>                      (range  10)        ;;  (0  1  2  ..  9)                    (filter  odd?)  ;;  (1  3  5  7  9)                    (map  inc)))      ;;  (2  4  6  8  10)     ;;  r  is  (2  4  6  8  10)    
  • 23. FuncFonal  programming   ;;  r  is  (2  4  6  8  10)   (reduce  +  r)     ;;  =>  30   (reductions  +  r)   ;;  =>  (2  6  12  20  30)         var  sum  =  _.reduce(r,  function(memo,  num){  return  memo  +  num;  });  
  • 24. Sequence  abstracFon   Data  structures  as  seqs   (first  [1  2  3])  ;;=>  1   (rest  [1  2  3])  ;;=>  (2  3)   General  seq  funcNons:  map,  reduce,  filter,  ...   (distinct  [1  1  2  3])  ;;=>  (1  2  3)   (take  2  (range  10))  ;;=>  (0  1)     See  hcp://clojure.org/cheatsheet  for  more    
  • 25. Sequence  abstracFon   Most  seq  funcNons  return  lazy  sequences:     (take  2  (map                        (fn  [n]  (js/alert  n)  n)                            (range)))     infinite  lazy  sequence  of  numbers   side  effect  
  • 26. Mutable  state:  atoms   (def  my-­‐atom  (atom  0))   @my-­‐atom  ;;  0   (reset!  my-­‐atom  1)   (reset!  my-­‐atom  (inc  @my-­‐atom))  ;;  bad  idiom   (swap!  my-­‐atom  (fn  [old-­‐value]                                      (inc  old-­‐value)))   (swap!  my-­‐atom  inc)  ;;  same   @my-­‐atom  ;;  4    
  • 27. Lisp:  macros   (map  inc        (filter  odd?            (range  10)))     (-­‐>>        (range  10)      (filter  odd?)      (map  inc))   thread  last  macro  
  • 28. Lisp:  macros   (macroexpand        '(-­‐>>  (range  10)  (filter  odd?)))     ;;  =>  (filter  odd?  (range  10))     (macroexpand        '(-­‐>>  (range  10)  (filter  odd?)  (map  inc)))     ;;  =>  (map  inc  (filter  odd?  (range  10)))    
  • 29. Lisp:  macros   JVM  Clojure:     (defmacro  defonce  [x  init]    `(when-­‐not  (exists?  ~x)          (def  ~x  ~init)))       ClojureScript:     (defonce  foo  1)   (defonce  foo  2)  ;;  no  effect   notes:     ●  macros  must  be  wricen  in  JVM  Clojure   ●  are  expanded  at  compile  Nme   ●  generated  code  gets  executes  in  ClojureScript  
  • 30. Part  3:  Full  Stack  Clojure  
  • 31. Full  Stack  Clojure     Front-end (js) ClojureScript reagent + react secretary cljs-http figwheel REPL leiningen core.async Prismatic/Schema timbre Server side (JVM) Clojure ring compojure liberator environ hiccup Framework: Pedestal Persistence RDBMS (via JDBC, e.g. PostgresQL, MySQL, H2, etc) clojure.java.jdbc YesQL Datomic
  • 32. Show  me  the  code!   https://github.com/borkdude/full-stack-clojure-han-okt-2015
  • 33. Get  started  with  Clojure(Script)   •  Read  a  Clojure(Script)  book   •  Do  the  4clojure  exercises   •  Start  hacking  on  your  own  project   •  Pick  an  online  Clojure  course     •  Join  the  AMSCLJ  meetup   •  Join  the  Slack  community