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
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. 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. Equality
(e a[rd "le "re")
df
"e" bu" gen]
(e b[rd "le "re")
df
"e" bu" gen]
( ab ; = tu
=
) ; > re
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. 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. 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. 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. 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. 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
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/
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. 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. 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. 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