Clojurescript
up and running
Timo Sulg, @timgluz
@Helsinki/JS, 27th November, 2013
What? And why?
Was? und warum?
source:
CoffeScript wiki has ~200 langs
JS as assembler for web
JavaScript is an assembly language. The JavaScript + HTML
generate is like a .NET assembly. The br...
Photoproof
Clojure's brith
Clojure?
1. Functional
2. Dynamically typed
3. Lisp
Clojure/Script?
Subset of Clojure
No concurrency primitives
Influences from Host
Inner parts

source: Stuart Sierra's "Clojure - getting up and running;"
Best parts
1.
2.
3.
4.
5.

Generic data primitives
Highly composable
Expressinevess
Extensible
core.async
Little peak into syntax
quick steptrough
source: Kanaka's cheatsheet
Getting started
; it j cnoe
; no s osl
(lgj/osl "el wrd";
.o scnoe Hlo ol!)
; it BosrRP
; no rwe EL
(rnl "el wrd)
pitn Hlo...
Code modularity
(scj.ol.el
n lswrdhlo
(rqie'sassn:ssn)
:eur [tr.u a u]
(ue'paeserh:ny[a,ngt :serh)
:s [lnt.at ol dy ih] a ...
Primitive collections
; ary
; ras
(e a(ra)
df
ary)
(e a(ra 123)
df
ary
)
(gta1 ; 2
ae
) ;
; ojc
; bet
(e o(soj)
df
j-b)
(e...
Generic datastructures
; ls
; it
(e a(it123)
df
ls
)
(e b'123)
df
(
)
; vco
; etr
(e c(etr123)
df
vco
)
(e d[ 234)
df
1
]
...
Equality
(e a[rd "le "re")
df
"e" bu" gen]
(e b[rd "le "re")
df
"e" bu" gen]
( ab ; = tu
=
) ; > re
Conditionals
(f(o?(on bgnmes)
i ps cut u-ubr)
(rnl "o rayfrrlae)
pitn Nt ed o ees"
(rnl "eppsig)
pitn Ke uhn")
(hn( 0x1)
w...
Functions
#d-m %)
(ost 1
(o tebn'lc'#d-m %)
.n h-t cik (ost 1)
(e fn(n[ (rnl "o o fn")
df u f ] pitn Lt f u.))
(enfn[
df u...
Destructuring
; cnawy dsrcuei bnigepeso
; a las etutr n idn xrsin
; icuig lt fnto agmns los ec
; nldn, e, ucin ruet, op, t...
Variable arguments
; alagmnsbyn towl b pae i a
; l ruet eod w il e lcd n
; sqec budt rs
; eune on o et
(enfo[ b&rs]
df o a...
Named parameters &
defaults
(enfo[ {ky [a bz} ..
df o & :es br a]] .)
(o :a 1:a 2
fo br
bz )
(enfo[ {ky [a bz
df o & :es b...
Iterators
(oe [tm[,,]
dsq ie 123]
(rnl ie)
pitn tm)
(oie [ 5 (rnl "B")
dtms i ] pitn AC)
(op[ 0
lo i ]
(rnl i
pitn )
(eu (...
More
Joel Martin, @bus_kanaka, has done great job.
Source:
http://kanaka.github.io/clojurescript/web/synonym.html
Demos
Setting up
Interop with JS
Dommy in Action
Core.Async
Setting up
and getting running
Setting up environment
Download the lein script (or on Windows lein.bat)
Place it on your $PATH where your shell can find ...
Starting with new project
$> lein help new
$> lein new ex1_intro
Result
Change into this
Set up project's file
(epoete1ito"..-NPHT
dfrjc x_nr 010SASO"
:ecito "u iiilpoet"
dsrpin Or nta rjc.
:r "tp/eapecmFXE
ul h...
ex1_intro/core.cljs
(se1itocr
n x-nr.oe
; uewe yuwn t rp it ti pg
; s hn o at o el no hs ae
(rqie[ljr.rwe.el:srp])
:eur co...
index.html
<!<1i ="ra"Frtdm<h>
h d
ae1>is eo/1
<citsc"j/oej"<srp>
srp r=/scr.s>/cit
<cittp=tx/xml"
srp ye"eteape>
e1itocr....
Run it
$> lein deps ;; only when you changed deps
$> lein cljsbuild clean ;;
$> lein cljsbuild once ;; or use auto
$> lein...
REPLing with Rhino
$> lein trampoline cljsbuild repl-rhino
$> (dotimes [i 5] (println i))
$> :cljs/quit
Interop with JS
Leap.JS
Dommy
a app for FirefoxOS
Run it
$> lein repl
$> (require '[foxyeye.handler] :reload-all)
$> goto: 127.0.0.1:8080
...
$> (foxyeye.handler/stop-serve...
Mainpage
State of project
dependencies
Search
Dommy
(en^epr ii [
df :xot nt ]
(lgj/osl "erhapi iiilzd)
.o scnoe Sac p s ntaie"
(om/itn (e1:sac-t):lc o-erh
dmylse! sl #e...
Templating with Hiccups
(eur 'fxeevessac :ssac-iw)
rqie [oyy.iw.erh a erhve]
..
.
(enrne [ cnet
df edr & otn]
(tl
hm5
(nld...
Little Dommy in Action
; gtalslce lnugs
; e l eetd agae
(engtslce-ag [ slcos
df e-eetdlns & eetr]
(pl sr
apy t
(neps 
itro...
Core.async
the last demo
Links
https://github.com/timgluz/heljs
https://github.com/clojure/clojurescript
http://clojure.org/cheatsheet
https://hime...
THE END
@timgluz
Upcoming SlideShare
Loading in...5
×

Clojurescript up and running

881
-1

Published on

My talk at Helsinki/JS. I gave short introduction to Clojurescript and how set up your first projects with demos.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
881
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Clojurescript up and running

  1. 1. Clojurescript up and running Timo Sulg, @timgluz @Helsinki/JS, 27th November, 2013
  2. 2. What? And why? Was? und warum?
  3. 3. source: CoffeScript wiki has ~200 langs
  4. 4. JS as assembler for web JavaScript is an assembly language. The JavaScript + HTML generate is like a .NET assembly. The browser can execute it, but no human should really care what’s there. - Erik Meijer, author of Rx and Linq source: Scott Hansemal's blog
  5. 5. Photoproof
  6. 6. Clojure's brith
  7. 7. Clojure? 1. Functional 2. Dynamically typed 3. Lisp
  8. 8. Clojure/Script? Subset of Clojure No concurrency primitives Influences from Host
  9. 9. Inner parts source: Stuart Sierra's "Clojure - getting up and running;"
  10. 10. Best parts 1. 2. 3. 4. 5. Generic data primitives Highly composable Expressinevess Extensible core.async
  11. 11. Little peak into syntax quick steptrough source: Kanaka's cheatsheet
  12. 12. Getting started ; it j cnoe ; no s osl (lgj/osl "el wrd"; .o scnoe Hlo ol!) ; it BosrRP ; no rwe EL (rnl "el wrd) pitn Hlo ol"
  13. 13. Code modularity (scj.ol.el n lswrdhlo (rqie'sassn:ssn) :eur [tr.u a u] (ue'paeserh:ny[a,ngt :serh) :s [lnt.at ol dy ih] a at])
  14. 14. Primitive collections ; ary ; ras (e a(ra) df ary) (e a(ra 123) df ary ) (gta1 ; 2 ae ) ; ; ojc ; bet (e o(soj) df j-b) (e o(soj"o"1"a"2) df j-b fo br )
  15. 15. Generic datastructures ; ls ; it (e a(it123) df ls ) (e b'123) df ( ) ; vco ; etr (e c(etr123) df vco ) (e d[ 234) df 1 ] ; st ; es (e f(e 1123) df st ) (e g#123) df {,,} ; hs-as ; ahmp (e h(ahmp:o 1:a 2:a 3) df hs-a fo br bz ) (e i{fo1 :a 2 :a 3) df :o , br , br }
  16. 16. Equality (e a[rd "le "re") df "e" bu" gen] (e b[rd "le "re") df "e" bu" gen] ( ab ; = tu = ) ; > re
  17. 17. Conditionals (f(o?(on bgnmes) i ps cut u-ubr) (rnl "o rayfrrlae) pitn Nt ed o ees" (rnl "eppsig) pitn Ke uhn") (hn( 0x1) we > 2 (t "ai tevle) sr vld i au") (od cn ( n0 "eaie < ) ngtv" ( n0 "oiie > ) pstv" :le"eo) es zr")
  18. 18. Functions #d-m %) (ost 1 (o tebn'lc'#d-m %) .n h-t cik (ost 1) (e fn(n[ (rnl "o o fn") df u f ] pitn Lt f u.)) (enfn[ df u ] (rnl "o o fn") pitn Lt f u.) (e fn df u "eei eapeo mlil aiy hr s xml f utpe rt" (]nl [ i) (_ 1 [] ) (__ 2 [ ] ) (___ 3) [ ] )
  19. 19. Destructuring ; cnawy dsrcuei bnigepeso ; a las etutr n idn xrsin ; icuig lt fnto agmns los ec ; nldn, e, ucin ruet, op, t. (e m{frt"o" df :is Bb :ide"" mdl J :at"mt") ls Sih} (e [:es[is mdl ls] m lt {ky frt ide at} ] .. .) (e clr[5 251005) df oo 25 5 0 .] (e [rg_a clr lt [ ] oo] .. .)
  20. 20. Variable arguments ; alagmnsbyn towl b pae i a ; l ruet eod w il e lcd n ; sqec budt rs ; eune on o et (enfo[ b&rs] df o a et .. .)
  21. 21. Named parameters & defaults (enfo[ {ky [a bz} .. df o & :es br a]] .) (o :a 1:a 2 fo br bz ) (enfo[ {ky [a bz df o & :es br a] :r{a "eal1, o br dfut" bz"eal2}].. a dfut"} .)
  22. 22. Iterators (oe [tm[,,] dsq ie 123] (rnl ie) pitn tm) (oie [ 5 (rnl "B") dtms i ] pitn AC) (op[ 0 lo i ] (rnl i pitn ) (eu (n i) rcr ic )) ;frmprdc;itr ;o;a;euefle
  23. 23. More Joel Martin, @bus_kanaka, has done great job. Source: http://kanaka.github.io/clojurescript/web/synonym.html
  24. 24. Demos Setting up Interop with JS Dommy in Action Core.Async
  25. 25. Setting up and getting running
  26. 26. Setting up environment Download the lein script (or on Windows lein.bat) Place it on your $PATH where your shell can find it (eg. ~/bin) Set it to be executable (chmod a+x ~/bin/lein) Check the version: $> lein version more info: http://leiningen.org/
  27. 27. Starting with new project $> lein help new $> lein new ex1_intro
  28. 28. Result
  29. 29. Change into this
  30. 30. Set up project's file (epoete1ito"..-NPHT dfrjc x_nr 010SASO" :ecito "u iiilpoet" dsrpin Or nta rjc. :r "tp/eapecmFXE ul ht:/xml.o/IM" :ies {nm "cis Pbi Lcne lcne :ae Elpe ulc ies" :r "tp/wwelpeoglglelv0hm" ul ht:/w.cis.r/ea/p-1.tl} :eednis[;ht:/w.esoeecmjv/r.ljr:ljr/.. dpnece ;tp/wwvriny.o/aaogcouecoue151 [r.ljr/ljr ".." ogcouecoue 151] ;ht:/w.esoeecmjv/r.ljr:ljrsrp/.-00 ;tp/wwvriny.o/aaogcouecouecit0023 [r.ljr/ljrsrp ".-00] ogcouecouecit 0023" [enlgtnel".."] li-ih-rp 007] :lgn [li-lsul "..-NPHT]; mkscouecitn ese puis [encjbid 101SASO" ; ae ljrsrpig air [ensmltn".."] li-ipeo 120] :elotos{nelmdlwr [ihtbenelhnlrlgtal-p] rp-pin :rp-ideae lgtal.rp.ade/ihtbeos} ; cmrhnieeape hts/gtu.o/mzseli-lsul/lbmse/ape ; opeesv xml: tp:/ihbcmeeek/encjbidbo/atrsml :lsul { cjbid :uls[ bid { ;Tept t tetplvlCouecitsuc drcoy h ah o h o-ee ljrSrp ore ietr: :orepts[sccj" suc-ah "r/ls] :oplr{ cmie :uptt "eore/ulcj/oej" otu-o rsucspbi/scr.s :piiain :htsae;:oe :ipe :dacd otmztos wiepc nn, sml, avne :annstu wrig re :rtypittu}]) pet-rn re}}
  31. 31. ex1_intro/core.cljs (se1itocr n x-nr.oe ; uewe yuwn t rp it ti pg ; s hn o at o el no hs ae (rqie[ljr.rwe.el:srp]) :eur couebosrrp a el) (en^epr mi [ df :xot an ] ;sryaotta ;or bu ht (wiej/ouet .rt sdcmn "h sye""oo:e;">Hlo HlJ!/1" <1 tl=clrrd" el, e/S<h>) ;ti pr i rqie frcnetn it brp ;hs at s eurd o oncig no -el (elcnet"tp/lclot90/el) rp/onc ht:/oahs:00rp")
  32. 32. index.html <!<1i ="ra"Frtdm<h> h d ae1>is eo/1 <citsc"j/oej"<srp> srp r=/scr.s>/cit <cittp=tx/xml" srp ye"eteape> e1itocr.an) /cligorfrtap x_nr.oemi(; /aln u is p; <srp> /cit -> -
  33. 33. Run it $> lein deps ;; only when you changed deps $> lein cljsbuild clean ;; $> lein cljsbuild once ;; or use auto $> lein simpleton 3000 file :from resources/public $> goto http://127.0.0.1:3000/index
  34. 34. REPLing with Rhino $> lein trampoline cljsbuild repl-rhino $> (dotimes [i 5] (println i)) $> :cljs/quit
  35. 35. Interop with JS Leap.JS
  36. 36. Dommy a app for FirefoxOS
  37. 37. Run it $> lein repl $> (require '[foxyeye.handler] :reload-all) $> goto: 127.0.0.1:8080 ... $> (foxyeye.handler/stop-server)
  38. 38. Mainpage
  39. 39. State of project dependencies
  40. 40. Search
  41. 41. Dommy (en^epr ii [ df :xot nt ] (lgj/osl "erhapi iiilzd) .o scnoe Sac p s ntaie" (om/itn (e1:sac-t):lc o-erh dmylse! sl #erhbn cik nsac) (oe [tm(e :fct-agaeie) dsq ie sl .aeslnug-tm] (om/itn ie :lc tgl-aesie)) dmylse! tm cik ogefct-tm)
  42. 42. Templating with Hiccups (eur 'fxeevessac :ssac-iw) rqie [oyy.iw.erh a erhve] .. . (enrne [ cnet df edr & otn] (tl hm5 (nld-s "csmdr.s" icuecs /s/oencs "csmdr-epniecs /s/oenrsosv.s" "csapcs) /s/p.s" [bd.erucs :oymtois [scinapiain{cas"rdcnee" :eto#plcto :ls gi etrd :tl "a-it:30x bcgon:wie" sye mxwdh 8p; akrud ht;} cnet]) otn]) (edr(erhve sac-tm) rne sac-iw erhies) Source: foxyeye.search.cljs
  43. 43. Little Dommy in Action ; gtalslce lnugs ; e l eetd agae (engtslce-ag [ slcos df e-eetdlns & eetr] (pl sr apy t (neps itroe , (o [eetd(e slcos] fr slce sl eetr) (om/trslce :aalnug))) dmyat eetd dt-agae)) Source: foxyeye.search.cljs
  44. 44. Core.async the last demo
  45. 45. Links https://github.com/timgluz/heljs https://github.com/clojure/clojurescript http://clojure.org/cheatsheet https://himera.herokuapp.com/synonym.html https://github.com/magomimmo/modern-cljs http://kanaka.github.io/clojurescript/web/synonym.html http://lukevanderhart.com/2011/09/30/using-javascriptand-clojurescript.html
  46. 46. THE END @timgluz
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×