Skip to content
Newer
Older
100644 204 lines (203 sloc) 7.68 KB
d0b323e @richhickey doc updates
richhickey authored
1 * ClojureScript Day #1
2 * Important things to note
3 ** This should be a dialog, not a lecture
4 *** stop me, ask questions, understand deeply
5 ** There are still many things I don't know or haven't decided
6 *** some tasks will be research
7 *** some pushback welcome
8 **** I reserve BDFL rights :)
9 ** This is an opportunity to get involved early
10 *** stay flexible to avoid pain
11 ** Welcome Chouser!
12 *** One of my first and best users and contributors
13 *** Someone whose opinions I value, and a Clojure expert
14 *** Author of a Clojure book not (yet) working at Relevance!
15 *** The first to walk down the ClojureScript road
16 ** This is a key Clojure/core (with help) deliverable
17 *** We do more than maintain, we lead
18 **** community should be stunned (shhh!)
19 *** I'm very excited about this aspect
20 **** let's knock this out of the park!
21 * Intro and rationale
22 ** Problem statement
23 *** Javascript is the only programmable technology in key target environments
24 **** i.e. the browser
25 **** nothing will change that for years to come
26 *** Javascript has the greatest reach in other key environments
27 **** i.e. mobile
28 *** Javascript (the language) is not very robust
29 **** Fewer good parts than bad parts
30 **** Much convention and discipline required to avoid headaches
31 **** Conventions differ between shops, libs
32 *** Ever increasing pressure to create richer applications in these environments
33 **** requiring more and larger libraries
34 ***** ordinary minification doesn't scale up
35 **** increasing requirements complexity
36 ***** can't add language or environment complexity on top
37 ** Rationale
38 *** solving this problem will give developers important leverage
39 *** empower them to tackle more difficult problems
40 **** with greater confidence in the robustness of their solutions
41 *** inspire next-generation approaches to web and mobile development
42 * Strategy
43 ** Compile (a subset of) Clojure to Javascript
44 *** reach everywhere JS does
45 ** Clojure is simpler, more robust, more concise, more powerful overall than JS
46 *** yet maps well to JS as implementation artifact
47 ** Leverage best-of-breed JS appraoches
48 *** Currently, IMO that is Google's, with Closure compiler and libraries
49 **** called gclosure hereafter
50 *** Fortunately both open sourced
51 *** Gclosure's strategy is whole-program optimization
52 **** resulting application includes only code actually used
53 **** this is essential to writing large (and small) applications against large and manifold libraries
54 ***** while allowing those libs to be written in a straightforward, non-clever manner
55 ** This is not just about the browser
56 *** Node.js, plugins anywhere JS is accepted, any future JS-based environments
57 ** Non-objectives
58 *** complete Closure
59 **** subset, but try to make identical features identical
60 **** document differences
61 *** porting large applications in their entirety
62 **** portability layers unifying JS and Java
63 **** cross platform reach is about moving core competencies and libraries, not everything
64 ** Profit!
65 *** ClojureScript becomes the most powerful language for generating the smallest and fastest JS applications
66 **** ClojureScript runs everywhere JS runs
67 *** This is Clojure's client story
68 *** This is Clojure's mobile story
69 *** A powerful tool for anyone willing to learn Clojure
70 * Tactics
71 ** Don't change Clojure itself
72 *** even though it might make things easier
73 **** track those things we'd like to be different, and work into Clojure dev schedule
74 ** The ClojureScript compiler is written in Clojure
75 *** The reader is Clojure's
76 *** Macros are written in Clojure
77 *** therefor, no compiler at runtime, *no eval*
78 **** browser-hosted REPL a non-target!
79 *** also, some things that are runtime-reified in Clojure (namespaces, Vars) may not be in ClojureScript
80 ** GClosure's strategy requires JS to be written in a particular idiom
81 *** especially for the most advanced optimization
82 *** ClojureScript will always generate code compliant with advanced optimizations
83 *** ClojureScript will use the same packaging and dependency strategy as gclosure
84 ** The gclosure library is an accepted dependency
85 *** but *nothing else* (other than base JS)
86 **** ok, and maybe some stealing from GWT output, if we're desperate
87 ***** but that's really it
88 *** in particular, use gclosure for all environmental conditionality
89 **** we make no per-browser decisions ourselves
90 ** The gclosure compiler is optional, but recommended for final delivery
91 *** but don't be too stupid without it
92 ** The compiler has an enriched primitive set (vs Clojure's)
93 *** deftype
94 *** defprotocol
95 *** extend-type
96 *** need no runtime lib
97 **** allows bootstrap abstraction and data structures to be written in terms of these
98 ** The runtime library is completely written in ClojureScript
99 *** No Javascript!
100 *** js* primitive escape hatch to reach gnarly stuff that ClojureScript won't expose
101 ** Presumptions
102 *** JS is single-threaded, forever
103 **** nevertheless, we will use Clojure reference primitives (at least atom)
104 * Roadmap
105 ** Compiler
106 *** It's alive!
107 *** a few more primitives to go
108 *** output needs to be sussed out
109 **** esp tested with gclosure compiler
110 *** some niceties missing (load-file etc)
111 ** Libraries
112 *** Many core macros imported and work
113 **** testing required
114 **** some missing, like binding, dotimes
115 *** This space intentionally left blank (core.cljs)
116 **** that's why you're here!
117 **** Much work, but following trodden ground
118 ***** Move the core abstractions to protocols
119 ***** Implement the core data structures with deftype
120 ***** copy fn impls, tweaking as needed
121 ** Tooling
122 *** ClojureScript written to the spec of gclosure
123 *** Actual integration with tool chain TODO
124 **** Deps builder
125 **** Compilation with gclosure compiler
126 ***** drive through API for greatest control vs CLI
127 **** finding/loading gclosure lib
128 **** testing
129 **** delivery
130 *** REPL and other expected dev conveniences
131 **** load (file), load-js
132 * Inside the compiler
133 ** I will not be the only one who knows this!
134 *** only 500 lines
135 ** [[http://en.wikipedia.org/wiki/Recursive_descent_parser][Recursive descent parser]]
136 ** 2 phases
137 *** analyze
138 **** code data in -> AST data out
139 ***** all ordinary Clojure data
140 **** each expr recursively analyzes nested exprs
141 **** checks for correct structure
142 *** emit
143 **** AST data in -> print JS (via side effect to *out*)
144 ***** this allows with-out-str, or direct to file
145 ***** alternative - thread output stream, meh
146 **** each expr recursively emits nested exprs
147 ** Both analyze and emit are polymorphic
148 *** using multimethods
149 *** other than a little hand-routing at top of analyze, no global switch statement
150 **** extend the compiler by defining parse and emit methods
151 **** add special ops to specials set
152 ** The threaded environment (env)
153 *** most important, :context and :locals
154 *** all name-introducing exprs (e.g. fn, let) augment the environment before passing to children
155 ** Tricky bit - :context
156 *** In ClojureScript everything is an expression
157 **** but not in JS
158 **** optimal output requires knowledge of the context
159 ***** :statement, :return, :expr
160 **** non-exprs in expr contexts require transformation (usually a function wrapper)
161 ** Primitives walkthrough
162 *** if
163 *** def
164 *** fn*
165 *** do
166 *** let*
167 *** loop*
168 *** recur
169 *** new
170 *** set!
171 *** ns
172 *** deftype*
173 *** .
174 *** js*
175 ** Macros walkthrough
176 *** macroexpansion
177 *** defprototype
178 *** extend-type
179 *** import-macros
180 *** the core/core trick
181 ** Evaluation model
182 *** top down, form at a time
183 **** just like Clojure
184 **** just like JS
185 ** What's missing?
186 *** validation that compilation ns resolved names exist in ns
187 *** more correctness checking
188 *** better error messages
189 **** ...
190 *** strategy for apply
191 * What's where
192 ** src/clj/cljs/compiler.clj
193 *** the compiler
194 ** src/clj/cljs/core.clj
195 *** core macros
196 ** src/cljs/core.cljs
197 *** core library
198 * Todo
199 ** separate org file
200 * Breakout and tackle tasks
201 ** we'll substantially be in the same file
202 *** ideas for making that work?
203 * Regroup and feedback
Something went wrong with that request. Please try again.