Skip to content
This repository
Browse code

merge master and new_text branches

  • Loading branch information...
commit 57890f5e97ab3ffecf3b42c5db2d31cc26e87908 2 parents 2f2f59c + 3815723
Paolo "Nusco" Perrotta nusco authored
4 resources/public/javascript/tryclojure.js
@@ -166,8 +166,8 @@ var controller;
166 166
167 167 $(document).ready(function() {
168 168 controller = $("#console").console({
169   - welcomeMessage:'Enter some Clojure code to be evaluated.',
170   - promptLabel: 'Clojure> ',
  169 + welcomeMessage:'Give me some Clojure:',
  170 + promptLabel: '> ',
171 171 commandValidate: onValidate,
172 172 commandHandle: onHandle,
173 173 autofocus:true,
12 resources/public/tutorial/page1.html
... ... @@ -1,15 +1,7 @@
1 1 <p>
2   - This tutorial isn't entirely complete yet. More fun content is to be written. Stay tuned.
  2 + I'll take you on a 5-minutes tour of Clojure, but feel free to experiment on your own along the road!
3 3 </p>
4 4
5 5 <p>
6   - Above, you have your REPL. Please try the examples as we go along, and by all means experiment
7   - with concepts independently. Should you refuse, you will promptly be IP banned from this
8   - website, and a teddy bear will eat your candies. ctrl+v to paste and ctrl+c to copy like you
9   - would normally expect, but you can't paste with your browser's right-click menu.
10   -</p>
11   -
12   -<p>
13   - You can type 'next' to move forward, 'back' to go back to the previous step, and 'restart' to
14   - restart the tutorial. Go ahead and type 'next' to begin
  6 + You can type <code>next</code> to skip forward, <code>back</code> to return to the previous step, and <code>restart</code> to get back to the beginning. Let's get started: type <code>next</code>.
15 7 </p>
35 resources/public/tutorial/page10.html
... ... @@ -1,30 +1,35 @@
1   -<p>Awesome. Now you can call this function just like we called the old square function.</p>
  1 +<p>
  2 + Success! Now you can call this new <code>square</code> function just like you called the old <code>square</code> function.
  3 +</p>
2 4
3 5 <p>
4   - Clojure has a great set of immutable and persistent data structures. Vectors, lists, maps, sets,
5   - I get chills.
  6 + By now, you know that lists are quite important in Clojure.
  7 + But Clojure also has other data structures:
6 8 </p>
7 9
8 10 <p>
9 11 Vectors: <code class="expr">[1 2 3 4]</code><br/>
10 12 Maps: <code class="expr">{:foo "bar" 3 4}</code><br/>
11   - Lists: <code class="expr">'(1 2 3 4)</code><br/>
12 13 Sets: <code class="expr">#{1 2 3 4}</code><br/>
13   - Vectors and lists are sequential and ordered collections. You'll see vectors used much more than lists.
14   - Maps are typical hash-maps - unordered collections indexed by keys. The keys can be any object. Here,
15   - we've used a keyword, <code>:foo</code> as a key. Keywords make excellent keys. We also used a number.
16   - Sets are mathematical sets.
17 14 </p>
18 15
19 16 <p>
20   - Clojure's collections are one of the most imporant parts of Clojure. Being a functional language, Clojure
21   - encourages immutability and as little state as possible. Therefore, instead of for loops mutating variables
22   - and such, most of the time you'll see higher order functions doing transformations on immutable data and
23   - returning new collections rather than ever modifying the old one.
  17 + Vectors and lists are sequential and ordered collections.
  18 + Sets are not ordered, and they cannot contain duplicate elements.
  19 + Maps are key-value collections, where the keys can be any object.
  20 + Here, we've used what Clojure calls a <em>keyword</em> (<code>:foo</code>) for one of the keys, and a number for the other key.
  21 +</p>
  22 +
  23 +<p>
  24 + Now I'll tell you another thing that may surprise you: Clojure collections are <em>immutable</em> - they can never change.
  25 + When you do anything on a list, including adding and removing elements, you actually get a brand new list.
  26 + (Fortunately, Clojure is amazingly efficient at creating new lists).
  27 + In general, Clojure encourages you to have as little mutable state as possible.
  28 + For example, instead of "for" loops and other state-changing constructs, most of the time you'll see functions doing transformations on immutable data and returning new collections, without changing the old one.
24 29 </p>
25 30
26 31 <p>
27   - A prime example of this is <code>map</code>. We can use map, a higher order function (which is a function
28   - that takes functions as arguments or returns functions), to 'map' a function to every element of a sequence.
29   - Let's use this to increment each number in a vector. Type <code class="expr">(map inc [1 2 3 4])</code> to continue.
  32 + A prime example of this is <code>map</code>. <code>map</code> is a <em>higher order function</em>, which means that it takes another function as an argument.
  33 + For example, you can ask <code>map</code> to increment each number in a vector by passing it the <code>inc</code> function, followed by the vector.
  34 + Try it for yourself: type <code class="expr">(map inc [1 2 3 4])</code> to continue.
30 35 </p>
13 resources/public/tutorial/page11.html
... ... @@ -1,8 +1,11 @@
1   -<p>Excellent work.</p>
  1 +<p>Great job!</p>
2 2
3 3 <p>
4   - Well, that's all there is right now. This tutorial is still a work in progress, and I'm working on more
5   - steps. If anybody wants to contribute, you can find a link to the Github repository on the 'about' page.
6   - Furthermore, if you're just a brand new Clojure developer looking for some learning experiences, check
7   - out the 'links' page. You'll find links to some tutorials and such there.
  4 + We've only scratched the surface of Clojure and its mind-bending power.
  5 + This tutorial is still a work in progress, and I'm working on more steps.
  6 + Meanwhile, you can learn more about Clojure by visiting the 'links' page.
  7 +</p>
  8 +
  9 +<p>
  10 + Welcome to your adventures in Clojure, and be prepared to be surprised and delighted every step of the way!
8 11 </p>
7 resources/public/tutorial/page2.html
... ... @@ -1,6 +1,7 @@
1 1 <p>
2   - I bet you're curious to find out what Clojure code looks like, aren't you? Sure you are.
3   - Well, I've give you a hint: it's made up of lists. Let's do some arithmetic.
  2 + The first thing you may notice about Clojure is that common operations look... strange.
4 3 </p>
5 4
6   -<code class="expr">(+ 3 3)</code>
  5 +<p>
  6 + For example, try typing <code class="expr">(+ 3 3)</code> in the REPL.
  7 +</p>
13 resources/public/tutorial/page3.html
... ... @@ -1,12 +1,13 @@
1 1 <p>
2   - Excellent work! There are other arithmetic functions.
  2 + That was a strange way to say "three plus three", wasn't it?
3 3 </p>
4   -<code>*</code>
5   -<code>-</code>
6   -<code>/</code>
7 4
8 5 <p>
9   - Try them out. Save <code>/</code> for last (don't worry, I have a reason!).
  6 + A Clojure program is made of <em>lists</em>.
  7 + <code class="expr">(+ 3 3)</code> is a list that contains an operator, and then the operands.
  8 + Try out the same concept with the <code>*</code> and <code>-</code> operators.
10 9 </p>
11 10
12   -<p>Once you're finished playing around, try <code class="expr">(/ 10 3)</code>.</p>
  11 +<p>
  12 + Division might surprise you. When you're ready to move forward, try <code class="expr">(/ 10 3)</code>.
  13 +</p>
8 resources/public/tutorial/page4.html
... ... @@ -1,8 +1,4 @@
1 1 <p>
2   - I bet that caught you by surprise, didn't it? Don't fear! Clojure simply has a built in Rational type.
3   - We can prove that we've got a rational by running <code class="expr">(type (/ 10 3))</code>. Rationals are more
4   - concise and precise than floating point numbers. However, we can force Clojure to do floating point
5   - division by just making one of our numbers floating point.
  2 + Now, that was a bit surprising: Clojure has a built in Rational type.
  3 + You can still force Clojure to do floating point division by making one of the operands floating point: type <code class="expr">(/ 10 3.0)</code> to continue.
6 4 </p>
7   -
8   -<p>Type <code class="expr">(/ 10 3.0)</code> to continue.</p>
9 resources/public/tutorial/page5.html
... ... @@ -1,11 +1,6 @@
1 1 <p>Awesome!</p>
2 2
3 3 <p>
4   - Another neat thing about Clojure is that functions can take an arbitrary number of arguments.
5   - Functions are allowed to specify a 'catch-all' to put an optional and arbitrary number of arguments
6   - into. Because of this, a lot of Clojure's core functions have interesting capabilities. For example
7   - the arithmetic functions we've already played with are not limited to two arguments! No sir, they can
8   - take any number of arguments they wish.
  4 + Many Clojure functions can take an arbitrary number of arguments.
  5 + Try it out: type <code class="expr">(+ 1 2 3 4 5 6)</code> to continue.
9 6 </p>
10   -
11   -<p>Try it out. Type <code class="expr">(+ 1 2 3 4 5 6)</code> to continue.</p>
9 resources/public/tutorial/page6.html
... ... @@ -1,7 +1,8 @@
1   -<p>Alright, that's enough math. Let's do some fun stuff, like write functions.</p>
2   -
3 1 <p>
4   - You can define functions in Clojure with <code>defn</code>
  2 + That's enough math. Let's do some fun stuff, like defining functions.
  3 + You can do that in Clojure with <code>defn</code>.
5 4 </p>
6 5
7   -<p>Type <code class="expr">(defn square [x] (* x x))</code> to continue!</p>
  6 +<p>
  7 + Type <code class="expr">(defn square [x] (* x x))</code> to define a "square" function that takes a single number and squares it.
  8 +</p>
13 resources/public/tutorial/page7.html
... ... @@ -1,12 +1,13 @@
1   -<p>Oh boy! We wrote our very own function! It's a lovely one, isn't it?</p>
  1 +<p>Congratulations - you just defined your first Clojure function. Many more will follow!</p>
2 2
3 3 <p>
4   - Our <code>square</code> function takes a single argument -- a number -- and squares it.
  4 + <code>defn</code> takes the name of the function, then the list of arguments, and then the body of the function.
  5 + I told you that a Clojure program is made of lists, right?
  6 + The entire <code>defn</code> is a list, and the function body is also a list.
  7 + (Even the arguments are collected in a vector, which is similar to a list - we'll talk about vectors soon).
5 8 </p>
6 9
7 10 <p>
8   - Take a look at how our defn form looks. First comes the name of the function, then the argument list
9   - (which is a vector, and not an actual list), then the body of the function.
  11 + Oh, sorry for talking so long - you probably want to try out your brand new function!
  12 + Type <code class="expr">(square 10)</code>.
10 13 </p>
11   -
12   -<p>But wait! We don't even know if our function works or not! Let's try it out. Type <code class="expr">(square 10)</code>.</p>
17 resources/public/tutorial/page8.html
... ... @@ -1,17 +1,20 @@
1 1 <p>Yay! It works!</p>
2 2
3 3 <p>
4   - You know, Clojure is a functional programming language. As such, it has first-class and
5   - anonymous functions. Let's write our square function as an anonymous function.
  4 + By now, you probably think that Clojure is very different from the programming languages you already know.
  5 + Indeed, it belongs to a different family than most popular languages' - the family of "functional" programming languages.
  6 + Like most functional languages, Clojure can define a function without even giving it a name:
6 7 </p>
  8 +
7 9 <code class="expr">(fn [x] (* x x))</code>
  10 +
8 11 <p>
9   - If you run this in the REPL above (as you should), you'll note that some very weird and
10   - cryptic thing is printed. Functions are just normal values like a number, a string, or
11   - anything else. The cryptic thing is simply how they look when printed.
  12 + If you run this code, you'll see some cryptic output.
  13 + In Clojure, functions are just normal values like numbers or strings.
  14 + <code>fn</code> defines a function and then returns it.
  15 + What you're seeing is simply what a function looks like when you print it on the screen.
12 16 </p>
13 17
14 18 <p>
15   - Our anonymous function isn't very useful if we don't call it. Let's do it. Type
16   - <code class="expr">((fn [x] (* x x)) 10)</code>
  19 + But wait - an anonymous function isn't very useful if you can't call it. Try to define a new anonymous function and call it straight away: <code class="expr">((fn [x] (* x x)) 10)</code>.
17 20 </p>
16 resources/public/tutorial/page9.html
... ... @@ -1,12 +1,16 @@
1 1 <p>
2   - Yay! Notice how we called our anonymous function? We just wrapped the function in parentheses,
3   - placing it as the first element in this new list and passing it arguments just like we did earlier
4   - with the arithmetic functions. Awesome, huh?
  2 + Let's see what you just did: you evaluated a list where the first element is the function itself, defined on the spot - and the other elements are the arguments that you pass to the function.
  3 + That's exactly the same syntax that you used earlier on to call functions like <code>square</code> or even <code>+</code>.
  4 + The only difference is that now you defined the function in the same place where you called it.
5 5 </p>
6 6
7 7 <p>
8   - You may not know this, but <code>defn</code> is actually just a bit of sugar around <code>def</code>
9   - and <code>fn</code> to create named functions. We can create named functions without <code>defn</code>
  8 + Remember <code>defn</code>?
  9 + Now I can tell you a secret: <code>defn</code> is actually just a bit of syntactic sugar around <code>def</code> and <code>fn</code>.
  10 + You've just seen <code>fn</code> at work: it defines a new function.
  11 + <code>def</code> binds the newly defined function to a name.
10 12 </p>
11 13
12   -<p>Type <code class="expr">(def square (fn [x] (* x x)))</code> to continue.</p>
  14 +<p>
  15 + If you want, you can create a named functions without using <code>defn</code>: type <code class="expr">(def square (fn [x] (* x x)))</code> to continue.
  16 +</p>
36 src/tryclojure/views/home.clj
@@ -15,26 +15,28 @@
15 15
16 16 (defpartial about-html []
17 17 [:p.bottom
18   - "Please note that this REPL is sandboxed, so you wont be able to do everything in it "
19   - "that you would in a local unsandboxed REPL. Keep in mind that this site is designed for "
20   - "beginners to try out Clojure and not necessarily as a general-purpose server-side REPL."]
  18 + "Welcome to Try Clojure - a quick tour of Clojure for absolute beginners."
  19 + ]
21 20 [:p.bottom
22   - "One quirk you might run into is that things you bind with def can sometimes disappear. "
23   - "The sandbox wipes defs if you def too many things, so don't be surprised. Furthermore, "
24   - "The sandbox will automatically be wiped after 15 minutes and if you evaluate more after that,"
25   - "It'll be in an entirely new namespace/sandbox."]
  21 + "Here is our only disclaimer: this site is an introduction to Clojure, not a generic Clojure REPL. "
  22 + "You won't be able to do everything in it that you could do in your local interpreter. "
  23 + "Also, the interpreter deletes the data that you enter if you define too many things, or after 15 minutes."]
26 24 [:p.bottom
27   - "TryClojure is written in Clojure and JavaScript (JQuery), powered by "
28   - (link-to "https://github.com/flatland/clojail" "clojail")
29   - " and Chris Done's "
30   - (link-to "https://github.com/chrisdone/jquery-console" "jquery-console")]
31   - [:p.bottom "Design by " (link-to "http://apgwoz.com" "Andrew Gwozdziewycz")])
  25 + "TryClojure is written in Clojure and JavaScript with "
  26 + (link-to "http://webnoir.org" "Noir") ", "
  27 + (link-to "https://github.com/flatland/clojail" "clojail") ", and Chris Done's "
  28 + (link-to "https://github.com/chrisdone/jquery-console" "jquery-console") ". "
  29 + " The design is by " (link-to "http://apgwoz.com" "Andrew Gwozdziewycz") "."
  30 + ])
32 31
33 32 (defpartial home-html []
34 33 [:p.bottom
35   - "Welcome to Try Clojure. See that little box up there? That's a Clojure repl. You can type "
36   - "expressions and see their results right here in your browser. We also have a brief tutorial to "
37   - "give you a taste of Clojure. Try it out by typing " [:code.expr "tutorial"] " in the console!"])
  34 + "Welcome to Clojure! "
  35 + "You can see a Clojure interpreter above - we call it a <em>REPL</em>."
  36 + ]
  37 + [:p.bottom
  38 + "Type \"tutorial\" in the REPL to begin."
  39 + ])
38 40
39 41 (defn root-html []
40 42 (html5
@@ -65,9 +67,7 @@
65 67 [:a#about.buttons.last "about"]]
66 68 [:div#changer (home-html)]]
67 69 [:div.footer
68   - [:p.bottom "©2011-2012 Anthony Grimes and numerous contributors. Built with "
69   - (link-to "http://webnoir.org" "Noir")
70   - "."]]
  70 + [:p.bottom "©2011-2012 Anthony Grimes and numerous contributors."]]
71 71 (javascript-tag
72 72 "var _gaq = _gaq || [];
73 73 _gaq.push(['_setAccount', 'UA-27340918-1']);

0 comments on commit 57890f5

Please sign in to comment.
Something went wrong with that request. Please try again.