diff --git a/.agignore b/.agignore new file mode 100644 index 00000000..e4beed02 --- /dev/null +++ b/.agignore @@ -0,0 +1,4 @@ +assets/reveal.js/ +assets/angular-1.4.5/ +prism.js +prism.clojure.js diff --git a/.gitignore b/.gitignore index 64421ffd..6157b8cf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .ruby-gemset _site .sass-cache +.bundle diff --git a/Gemfile b/Gemfile index e338201c..2b3324b4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,8 @@ # A sample Gemfile source "https://rubygems.org" -gem "github-pages" +require 'json' +require 'open-uri' +versions = JSON.parse(open('https://pages.github.com/versions.json').read) + +gem 'github-pages', versions['github-pages'] diff --git a/Gemfile.lock b/Gemfile.lock index 50e0768b..4fad3b85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,126 +1,129 @@ GEM remote: https://rubygems.org/ specs: - RedCloth (4.2.9) - activesupport (4.2.1) + activesupport (4.2.6) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - blankslate (2.1.2.4) - celluloid (0.16.0) - timers (~> 4.0.0) - classifier-reborn (2.0.3) - fast-stemmer (~> 1.0) + addressable (2.4.0) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.9.1.1) + coffee-script-source (1.10.0) colorator (0.1) - execjs (2.5.2) - fast-stemmer (1.0.2) - ffi (1.9.8) + ethon (0.9.0) + ffi (>= 1.3.0) + execjs (2.7.0) + faraday (0.9.2) + multipart-post (>= 1.2, < 3) + ffi (1.9.10) gemoji (2.1.0) - github-pages (35) - RedCloth (= 4.2.9) - github-pages-health-check (~> 0.2) - jekyll (= 2.4.0) + github-pages (82) + github-pages-health-check (= 1.1.0) + jekyll (= 3.1.6) jekyll-coffeescript (= 1.0.1) - jekyll-mentions (= 0.2.1) - jekyll-redirect-from (= 0.6.2) - jekyll-sass-converter (= 1.2.0) - jekyll-sitemap (= 0.8.1) - jemoji (= 0.4.0) - kramdown (= 1.5.0) - liquid (= 2.6.2) - maruku (= 0.7.0) + jekyll-feed (= 0.5.1) + jekyll-gist (= 1.4.0) + jekyll-github-metadata (= 2.0.0) + jekyll-mentions (= 1.1.2) + jekyll-paginate (= 1.1.0) + jekyll-redirect-from (= 0.10.0) + jekyll-sass-converter (= 1.3.0) + jekyll-seo-tag (= 2.0.0) + jekyll-sitemap (= 0.10.0) + jemoji (= 0.6.2) + kramdown (= 1.10.0) + liquid (= 3.0.6) + listen (= 3.0.6) mercenary (~> 0.3) - pygments.rb (= 0.6.1) - rdiscount (= 2.1.7) - redcarpet (= 3.1.2) + rouge (= 1.10.1) terminal-table (~> 1.4) - github-pages-health-check (0.3.1) - net-dns (~> 0.6) + github-pages-health-check (1.1.0) + addressable (~> 2.3) + net-dns (~> 0.8) + octokit (~> 4.0) public_suffix (~> 1.4) - hitimes (1.2.2) - html-pipeline (1.9.0) - activesupport (>= 2) - nokogiri (~> 1.4) + typhoeus (~> 0.7) + html-pipeline (2.4.1) + activesupport (>= 2, < 5) + nokogiri (>= 1.4) i18n (0.7.0) - jekyll (2.4.0) - classifier-reborn (~> 2.0) + jekyll (3.1.6) colorator (~> 0.1) - jekyll-coffeescript (~> 1.0) - jekyll-gist (~> 1.0) - jekyll-paginate (~> 1.0) jekyll-sass-converter (~> 1.0) jekyll-watch (~> 1.1) kramdown (~> 1.3) - liquid (~> 2.6.1) + liquid (~> 3.0) mercenary (~> 0.3.3) - pygments.rb (~> 0.6.0) - redcarpet (~> 3.1) + rouge (~> 1.7) safe_yaml (~> 1.0) - toml (~> 0.1.0) jekyll-coffeescript (1.0.1) coffee-script (~> 2.2) - jekyll-gist (1.2.1) - jekyll-mentions (0.2.1) - html-pipeline (~> 1.9.0) - jekyll (~> 2.0) + jekyll-feed (0.5.1) + jekyll-gist (1.4.0) + octokit (~> 4.2) + jekyll-github-metadata (2.0.0) + jekyll (~> 3.1) + octokit (~> 4.0) + jekyll-mentions (1.1.2) + html-pipeline (~> 2.3) + jekyll (~> 3.0) jekyll-paginate (1.1.0) - jekyll-redirect-from (0.6.2) - jekyll (~> 2.0) - jekyll-sass-converter (1.2.0) + jekyll-redirect-from (0.10.0) + jekyll (>= 2.0) + jekyll-sass-converter (1.3.0) sass (~> 3.2) - jekyll-sitemap (0.8.1) - jekyll-watch (1.2.1) - listen (~> 2.7) - jemoji (0.4.0) + jekyll-seo-tag (2.0.0) + jekyll (~> 3.1) + jekyll-sitemap (0.10.0) + jekyll-watch (1.4.0) + listen (~> 3.0, < 3.1) + jemoji (0.6.2) gemoji (~> 2.0) - html-pipeline (~> 1.9) - jekyll (~> 2.0) - json (1.8.2) - kramdown (1.5.0) - liquid (2.6.2) - listen (2.10.0) - celluloid (~> 0.16.0) + html-pipeline (~> 2.2) + jekyll (>= 3.0) + json (1.8.3) + kramdown (1.10.0) + liquid (3.0.6) + listen (3.0.6) rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) - maruku (0.7.0) - mercenary (0.3.5) - mini_portile (0.6.2) - minitest (5.6.1) + rb-inotify (>= 0.9.7) + mercenary (0.3.6) + mini_portile2 (2.1.0) + minitest (5.9.0) + multipart-post (2.0.0) net-dns (0.8.0) - nokogiri (1.6.6.2) - mini_portile (~> 0.6.0) - parslet (1.5.0) - blankslate (~> 2.0) - posix-spawn (0.3.11) - public_suffix (1.5.1) - pygments.rb (0.6.1) - posix-spawn (~> 0.3.6) - yajl-ruby (~> 1.2.0) - rb-fsevent (0.9.5) - rb-inotify (0.9.5) + nokogiri (1.6.8) + mini_portile2 (~> 2.1.0) + pkg-config (~> 1.1.7) + octokit (4.3.0) + sawyer (~> 0.7.0, >= 0.5.3) + pkg-config (1.1.7) + public_suffix (1.5.3) + rb-fsevent (0.9.7) + rb-inotify (0.9.7) ffi (>= 0.5.0) - rdiscount (2.1.7) - redcarpet (3.1.2) + rouge (1.10.1) safe_yaml (1.0.4) - sass (3.4.13) - terminal-table (1.4.5) + sass (3.4.22) + sawyer (0.7.0) + addressable (>= 2.3.5, < 2.5) + faraday (~> 0.8, < 0.10) + terminal-table (1.6.0) thread_safe (0.3.5) - timers (4.0.1) - hitimes - toml (0.1.2) - parslet (~> 1.5.0) + typhoeus (0.8.0) + ethon (>= 0.8.0) tzinfo (1.2.2) thread_safe (~> 0.1) - yajl-ruby (1.2.1) PLATFORMS ruby DEPENDENCIES - github-pages + github-pages (= 82) + json + +BUNDLED WITH + 1.12.1 diff --git a/README.md b/README.md index d18de2d4..18e01c32 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,9 @@ Choices of Capstone App - Part. 2 Supporting Materials -------------------- -* [Student Cheatsheet](outline/cheatsheet.md) | [PDF](ClojureBridgeCheatsheet-v1.pdf) -* [LightTable tutorial](http://docs.lighttable.com/tutorials/full/) + +* [Student Cheatsheet](outline/cheatsheet.md) | [PDF](ClojurebridgeCheatsheet-v2.pdf) + * [Old Curriculum](http://clojurebridge.github.io/curriculum/index.v0.html) Repositories diff --git a/TEACHING.md b/TEACHING.md index 983df323..15895ead 100644 --- a/TEACHING.md +++ b/TEACHING.md @@ -48,7 +48,7 @@ Saturday: Workshop - [curriculum](README.md#curriculum). Preparation ----------- -Print the ([markdown](outline/cheatsheet.md) or [pdf](ClojureBridgeCheatsheet-v1.pdf)) and hand it out to students at the beginning of the day on Saturday. +Print the ([markdown](outline/cheatsheet.md) or [pdf](ClojurebridgeCheatsheet-v2.pdf)) and hand it out to students at the beginning of the day on Saturday. Room Setup ---------- @@ -110,7 +110,7 @@ TODO: add tips under each heading. Supporting Materials -------------------- -* [Student cheatsheet](outline/cheatsheet.md) | [PDF](ClojureBridgeCheatsheet-v1.pdf) +* [Student cheatsheet](outline/cheatsheet.md) | [PDF](ClojurebridgeCheatsheet-v2.pdf) * [Slides](http://clojurebridge.github.io/curriculum) diff --git a/_config.yml b/_config.yml index c1abc1f2..7459b1be 100644 --- a/_config.yml +++ b/_config.yml @@ -1,6 +1,7 @@ # Site settings title: ClojureBridge Curriculum -email: your-email@domain.com +email: info@clojurebridge.org +baseurl: /curriculum description: > # this means to ignore newlines until "baseurl:" Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for @@ -13,15 +14,16 @@ github_username: ClojureBridge markdown: kramdown kramdown: input: GFM -pygments: false -baseurl: /curriculum + hard_wrap: false + syntax_highlighter_opts: + disable : true encoding: UTF-8 exclude: - Gemfile - Gemfile.lock - CONTRIBUTING.md - EDITING-CURRICULUM.md -- ClojureBridgeCheatsheet-v1.pdf +- ClojurebridgeCheatsheet-v2.pdf - TEACHING.md - background-reading.md - tmp diff --git a/_layouts/default.html b/_layouts/default.html index 7278751e..e555aa3f 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -25,5 +25,6 @@ + diff --git a/assets/clojurebridge.css b/assets/clojurebridge.css index b189cf75..eb3ae370 100644 --- a/assets/clojurebridge.css +++ b/assets/clojurebridge.css @@ -45,3 +45,30 @@ button.link { text-align:left; color:#555555; } +#back-to-outline { + display: block; + position: fixed; + left: 0; + bottom: 0; + width: 130px; + height: 130px; +} +/* largely stolen from http://meta.superuser.com/questions/4788/css-for-the-new-kbd-style */ +.reveal kbd +{ + -moz-border-radius:3px; + -moz-box-shadow:0 1px 0 rgba(0,0,0,0.2),0 0 0 2px #fff inset; + -webkit-border-radius:3px; + -webkit-box-shadow:0 1px 0 rgba(0,0,0,0.2),0 0 0 2px #fff inset; + background: rgba(255, 255, 255, 0.50); + border:1px solid #ccc; + border-radius:3px; + box-shadow:0 1px 0 rgba(0,0,0,0.2),0 0 0 2px #fff inset; + color:#333; + display:inline-block; + font-family: "Anonymous Pro",monospace + line-height:1; + margin:0 .1em; + padding:.05em .15em; + text-shadow:0 1px 0 #fff; +} diff --git a/assets/prism.clojure.js b/assets/prism.clojure.js index 1aec7d6e..ab1c27db 100644 --- a/assets/prism.clojure.js +++ b/assets/prism.clojure.js @@ -4,7 +4,7 @@ Prism.languages.clojure = { symbol: /:[a-z][-a-z0-9?]*/gi, boolean: /(^|[^-])(true|false)/g, number: /-?\b\d+([./]\d+)?\b/g, -punctuation: /[[\](){},]/g, -operator: /(\*|\+|\-\s|%|\/|<=|=>|>=|<|=|>)/, -keyword: /\b(apply|and|assoc|backward|case|count|cond|doseq|dotimes|lower-case|upper-case|catch|class|conj|cons|const|def|defn|dissoc|do|else|enum|export|extends|finally|first|fn|for|forward|get-in|get|if|implements|import|instanceof|interface|keys|last|let|list|map|max|merge|min|mod|name|new|nil|not|not=|nth|or|partial|print-str|println|private|quot|range|reduce|rem|rest|return|right|set|state-all|state|static|str|super|switch|throw|try|turtle-names|update-in|vals|var|vector|while|zero\\?)\b/, + punctuation: /[[\](){},]/g, + operator: /(\*|\+|\-\s|%|\/|<=|=>|>=|<|=|>)/, + keyword: /\b(apply|and|assoc|backward|case|count|cond|doseq|dotimes|lower-case|upper-case|catch|class|conj|cons|const|def|defn|dissoc|do|else|enum|export|extends|finally|first|fn|for|forward|get-in|get|if|implements|import|instanceof|interface|keys|last|let|list|map|max|merge|min|mod|name|new|nil|not|not=|nth|or|partial|print-str|println|private|quot|range|reduce|rem|rest|return|right|set|state-all|state|static|str|super|switch|throw|try|turtle-names|update-in|update|vals|var|vector|while|zero\\?)\b/, }; diff --git a/index.md b/index.md index 82326ca2..22ebe38e 100644 --- a/index.md +++ b/index.md @@ -28,22 +28,37 @@ Please look at [README.md](README.md) instead. :green_heart: :blue_heart: {% endcomment %} +### Part I: Basics + * [Introduction to Programming with Clojure](outline/intro.html) * [Simple Values](outline/simple_values.html) * [Data Structures](outline/data_structures.html) * [Functions](outline/functions.html) -* [Capstone App: Drawing Lines](https://github.com/ClojureBridge/drawing/blob/master/curriculum/first-program.md) +* [Your First Program: Drawing Lines](https://github.com/clojurebridge-berlin/drawing/blob/master/curriculum/first-program.md) * [Flow Control and Logic](outline/flow_control.html) * [[bonus module] Sequences](outline/sequences.html) -* Choices of Capstone App - Part. 2 + + +
+### Part II: Practical Applications + +#### Graphics with Quil +{:style="text-align: left;"} + +{:style="width: 100%;"} +* [Snowflakes](https://github.com/ClojureBridge/drawing/blob/master/curriculum/create-something.md) Animation +* [Land of Quil](http://landofquil.we-do-fp.berlin/) Several Quil examples you can try out + +  - - [Turtles Walk](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE-SAMPLES.md) (more function study) +#### Other applications +{:style="text-align: left;"} - - [Snowflakes](https://github.com/ClojureBridge/drawing/blob/master/curriculum/create-something.md) (animation) +{:style="width: 100%;"} +* [Twinkle Twinkle Little Star](https://github.com/ClojureBridge/tones/blob/master/curriculum/01-piano-chords.md) Making sounds with Overtone +* [Global Growth](https://github.com/ClojureBridge/global-growth) Web app with REST api +* [Caesar Cipher](http://clojurebridge.github.io/community-docs/docs/exercises/caesar-cipher/) Mini exercise of Strings and Characters +* [Turtles Walk](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE-SAMPLES.md) More function study - - [Twinkle Twinkle Little Star](https://github.com/ClojureBridge/tones/blob/master/curriculum/01-piano-chords.md) (making sounds) - - [Global Growth](https://github.com/ClojureBridge/global-growth) (web app with REST api) - - [Caesar Cipher](http://clojurebridge.github.io/community-docs/docs/exercises/caesar-cipher/) - (mini exercise of Strings and Characters)
diff --git a/outline/cheatsheet-quil.md b/outline/cheatsheet-quil.md new file mode 100644 index 00000000..f9a8ebed --- /dev/null +++ b/outline/cheatsheet-quil.md @@ -0,0 +1,113 @@ +# Quil Cheatsheet + +## Shapes + +```clj +(line x1 y1 x2 y2) +``` + +Draws a line (a direct path between two points) to the screen. `x1`, `y1`, +`x2`, and `y3` are all numbers which are being used as coordinates, or pixels +from the top left on your screen. + +```clj +(rect x y width height) +``` + +Draws a rectangle to the screen. `x` and `y` are coordinates. `width` and +`height` are how big the box is, again in numbers. + +```clj +(ellipse x y width height) +``` + +Draws an ellipse (oval) in the display window. + +## Color + +```clj +(color r g b a) +``` + +A color consists of four values. The first three values (red, green, blue in +values from `0` to `255`) will give a color. Provide a fourth value to set the +opacity. `(color 0 0 255 128)`, for example, is half-transparent blue. + +```clj +(background color) +``` + +This sets the whole canvas to one color. Great for erasing the screen every +draw. + +```clj +(fill color) +``` + +This sets the fill of shapes which are painted after calling this function. + +```clj +(stroke color) +``` + +This sets a stroke, a border around the shapes painted after. + +```clj +(no-fill) +(no-stroke) +``` + +These disable the fill and/or stroke of shapes to be drawn. For example: + +```clj +(background (color 255 0 0)) +(fill (color 0 0 255)) +(ellipse 100 100 30 30) +``` + +## Text + +```clj +(text your-text x y) +``` + +This displays your text on the screen at certain coordinates. + +## Mouse + +These are useful functions to get values from your mouse. Great if you want +move things on your screen. + +```clj +(mouse-x) ;=> number +(mouse-y) ;=> number +(mouse-pressed?) ;=> true/false +``` + +What do you think this does? + +```clj +(ellipse (mouse-x) (mouse-y) 30 30) +``` + +## Time + +```clj +(frame-count) ;=> number +``` + +The number of frames displayed since the program started. Give it a try while +wrapping it in `(mod num div)` a modulo function. For example: + +```clj +(ellipse 100 + 100 + (mod (frame-count) 30) + (mod (frame-count) 30)) +``` + +## More Quil functions + +The functions mentioned above are just a few simple ones to get you started. +The [API documentation](http://quil.info/api) lists all Quil's functions, of +which there are many! diff --git a/outline/data_structures.md b/outline/data_structures.md index cf8e03c7..badd8626 100644 --- a/outline/data_structures.md +++ b/outline/data_structures.md @@ -83,32 +83,18 @@ collections together. ``` -
-#### Example - -> When there are a couple of turtles, -> `(turtle-names)` command will return turtle names in the form of a -> vector. -{: ng-show="block41" .description} - -```clojure -(turtle-names) -;=> [:trinity :neo :oracle :cypher] -``` -
- -
#### Creation -> The next two functions are used to make new vectors. The `vector` -> function takes any number of items and puts them in a new vector. -> `conj` is an interesting function that you'll see used with all the -> data structures. With vectors, it takes a vector and an item and -> returns a new vector with that item added to the end of the vector. -> Why the name `conj`? `conj` is short for conjoin, which means to -> join or combine. This is what we're doing: we're joining the new -> item to the vector. +> Instead of writing a vector with square brackets, you can also use the vector +> function to create a vector. All arguments are collected and placed inside a new +> vector. +> +> `conj` takes a vector and some other values, and returns a new vector with the +> extra value added. `conj` is short for conjoin, which means to join or combine. +> This is what we're doing: we're joining the extra value to the vector. `conj` +> can be used with any kind of collection. Right now the only kind of +> collection we've encountered is a vector. {: ng-show="block61" .description} ```clojure @@ -146,21 +132,10 @@ be confusing.
-#### EXERCISE 1: See turtle names +#### EXERCISE: Make a vector {: .slide_title .slide} -* Go to `walk.clj` file -* Type `(add-turtle :neo)` and evaluate this line by hitting Cmd + - Enter or Ctrl + Enter (no shift key) -* Repeat adding turtles a couple of times with different names -* Type `(turtle-names)`, evaluate this line and see the result -
- -
-#### EXERCISE 2: Make a vector -{: .slide_title .slide} - -* Go to insta-REPL +* Go to your REPL * Make a vector of the high temperatures for the next 7 days in the town where you live. * Then use the `nth` function to get the high temperature for next @@ -204,21 +179,6 @@ be confusing. ```
-
-#### Example - -> When turtle received commands such that `forward` or `right`, -> those return the result as a form of map of map. -{: ng-show="block103" .description} - -```clojure -(forward 40) -;=> {:trinity {:length 40}} -(right 90) -;=> {:trinity {:angle 90}} -``` -
-
#### Creation @@ -255,13 +215,13 @@ be confusing. (count {:first "Sally" :last "Brown"}) ;=> 2 -(:first {:first "Sally" :last "Brown"}) +(get {:first "Sally" :last "Brown"} :first) ;=> "Sally" -(:last {:first "Sally"}) +(get {:first "Sally"} :last) ;=> nil -(:last {:first "Sally"} :MISS) +(get {:first "Sally"} :last :MISS) ;=> :MISS ```
@@ -289,24 +249,26 @@ be confusing. > After the creation, we want to save a new value associated to the > key. The `assoc` function can be used by assigning a new value to > the existing key. -> Also, there's handy function `update-in`. The function takes map and -> a key or list of keys with a function. The value of specified key will be the -> first argument of the given function. +> Also, there's handy function `update`. The function takes map and +> a key with a function. The value of specified key will be the first +> argument of the given function. +> The `update-in` function works like `update`, but takes a vector of keys +> to update at a path to a nested map. {: ng-show="block110" .description} ```clojure (def hello {:count 1 :words "hello"}) -(update-in hello [:count] inc) +(update hello :count inc) ;=> {:count 2, :words "hello"} -(update-in hello [:words] str ", world") -{:count 1, :words "hello, world"} +(update hello :words str ", world") +;=> {:count 1, :words "hello, world"} (def mine {:pet {:age 5 :name "able"}}) (update-in mine [:pet :age] - 3) -{:pet {:age 2, :name "able"}} +;=> {:pet {:age 2, :name "able"}} ``` @@ -327,82 +289,42 @@ be confusing. #### Vector of Maps ```clojure -(state-all) -;=> [{:trinity {:x -1.7484556000744965E-6, :y 39.99999999999996, :angle 90, :color [106 40 126]}} -{:neo {:x 21.213202971967114, :y 21.213203899225725, :angle 45, :color [0 64 0]}} -{:oracle {:x -49.99999999999981, :y -4.3711390001862375E-6, :angle 180, :color [43 101 236]}}] - -(def states (state-all)) -;=> #'clojurebridge-turtle.walk/states - -(first states) -;=> {:trinity {:x -1.7484556000744965E-6, :y 39.99999999999996, -:angle 90, :color [106 40 126]}} +(def characters + [{:name "Snoopy" + :species "dog"} + {:name "Woodstock" + :species "bird"} + {:name "Charlie Brown" + :species "human"}]) + +(:name (first characters)) +;;=> "Snoopy" + +(map :name characters) +;;=> ("Snoopy" "Woodstock" "Charlie Brown") ``` -
-#### Map of Maps - -```clojure -(def st (first states)) -;=> #'clojurebridge-turtle.walk/st - -st -;=> {:trinity {:x -1.7484556000744965E-6, :y 39.99999999999996, :angle -90, :color [30 30 30]}} - -(:trinity st) -;=> {:x -1.7484556000744965E-6, :y 39.99999999999996, :angle 90, :color [30 30 30]} - -(get-in st [:trinity :angle]) -;=> 90 -``` -
- - -
-#### EXERCISE 3: See turtles states -{: .slide_title .slide} - -* Go to `walk.clj` file -* Try examples of previous two slides -* See what values you get - -> Every time you write a line of code, -> hit Ctrl + Enter or Cmd + -> Enter (no shift key) to evaluate it one by one. - -```clojure -(state-all) -(def states (state-all)) -(first states) -(def st (first states)) -st -(:trinity st) -(get-in st [:trinity :angle]) -``` -
-#### EXERCISE 4: Modeling Yourself +#### EXERCISE: Modeling Yourself {: .slide_title .slide} -* Go to insta-REPL +* Using the Clojure REPL - (Option) You may create a new file and write code in the file. To - evaluate, paste code block on `lein repl` + evaluate, select the code you want and hit ctrl + shift + x or cmd shift + x, or press the "Eval" button * Make a map representing yourself * Make sure it contains your first name and last name * Then, add your hometown to the map using [assoc](http://grimoire.arrdem.com/1.6.0/clojure.core/assoc/) or [merge](http://grimoire.arrdem.com/1.6.0/clojure.core/merge/).
-#### EXERCISE 5 [BONUS]: Modeling your classmates +#### EXERCISE [BONUS]: Modeling your classmates {: .slide_title .slide} * First, take the map you made about yourself in previous exercise. * Then, create a vector of maps containing the first name, last name and hometown of two or three other classmates around you. -* Lastly, add your map to their information using [conj](http://grimoire.arrdem.com/1.6.0/clojure.core/conj/). +* Lastly, add your map to their information using [conj](http://clojuredocs.org/clojure.core/conj).
{% comment %} diff --git a/outline/flow_control.md b/outline/flow_control.md index 92f7a877..091aacc3 100644 --- a/outline/flow_control.md +++ b/outline/flow_control.md @@ -39,7 +39,7 @@ Flow Control #### Testing conditions to react > Software is also full of these decisions. *If* the user's input is -> valid, *then* we should save her data; *otherwise* we show an error +> valid, *then* we should save their data; *otherwise* we show an error > message. The common pattern here is that you test some condition and > react differently based on whether the condition is *true* or *false*. {: ng-show="block12" .description} @@ -49,31 +49,20 @@ Flow Control ### `if` {: .slide_title .slide} - - + > In Clojure, the most basic tool we have for the flow control is the `if` -> operator. Here's the example how you might code the data validation scenario. +> operator. It allows you to choose between two options depending upon a condition. {: ng-show="block21" .description} -> Here' an example. If adding 40 to `y` is still less than 150, then -> return `(+ y 40)`; otherwise, returns -150. (As for turtle app's -> frame, the top has 150 in y, while the bottom has -150 in y.) -{: ng-show="block22" .description} - > Reference: [Conditional `if`](http://clojurebridge.github.io/community-docs/docs/clojure/if/) -{: ng-show="block22" .description} +{: ng-show="block21" .description} ```clojure -(if (< (+ y 40) 150) - (+ y 40) - -150)) +(if (< age legal-drinking-age) + ["water" "soda"] + ["water" "soda" "beer" "wine"]) ``` - - -
-#### General form of `if` operator ```clojure (if conditional-expression @@ -82,22 +71,6 @@ ng-click="block21=!block21"> ```
-
-#### `if` examples - -```clojure -(if (> 3 1) - "3 is greater than 1" - "3 is not greater than 1") -;=> "3 is greater than 1" - -(if (> 1 3) - "1 is greater than 3" - "1 is not greater than 3") - ;=> "1 is not greater than 3" -``` -
-
#### Truthiness @@ -115,12 +88,16 @@ ng-click="block21=!block21"> "A string is considered true" "A string is not considered true") ;=> "A string is considered true" +``` +```clojure (if nil "nil is considered true" "nil is not considered true") ;=> "nil is not considered true" +``` +```clojure (if (get {:a 1} :b) "expressions which evaluate to nil are considered true" "expressions which evaluate to nil are not considered true") @@ -129,29 +106,47 @@ ng-click="block21=!block21">
-#### EXERCISE 1: Y value within a frame +#### EXERCISE 1: {: .slide_title .slide} -* Write a function `y-within-frame` that takes y (vertical position) as an argument. -* You may use if example in the slide. -* The function should return the y value that won't exceed 150. +* write a function `ordinal` that takes a number `n` as an argument +* start from the template on this slide +* if `n` equals `1`, then the function should return `"1st"`, otherwise it should return the number + `"th"` +* you will have to use the [`str`](http://clojurebridge-berlin.github.io/community-docs/docs/clojure/str/) function +* don't worry yet about "2nd" or "3rd" - - See: [x and y in absolute values](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE.md#x-and-y-in-absolute-values) +```clojure +(defn ordinal [n] + (if ;; condition + ;; then + ;; else + )) +``` ```clojure -;; if example -(if (< (+ y 40) 150) - (+ y 40) - -150)) +;; usage of ordinal function +(ordinal 1) ;=> "1st" +(ordinal 5) ;=> "5th" ``` +
+ +
+#### EXERCISE 2: +{: .slide_title .slide} + +* extend the `ordinal` function to correctly generate "2nd" and "3rd" +* hint: you can use an `if` inside another `if` ```clojure -;; usage of y-within-frame function -(y-within-frame 80) ;=> 120 -(y-within-frame 180) ;=> -150 +;; usage of the new ordinal function +(ordinal 1) ;=> "1st" +(ordinal 2) ;=> "2nd" +(ordinal 3) ;=> "3rd" +(ordinal 4) ;=> "4th" ```
+
### `cond` {: .slide_title .slide} @@ -165,22 +160,27 @@ ng-click="block21=!block21"> > To branch to multiple situations, `cond` operator works well. {: ng-show="block61" .description} -> Here's the example. If adding 40 to y exceeds 150, evaluate the -> first form. In this case, it returns -150. If adding 40 to y is less -> than -150, evaluate the second form. In this case, it returns 150. -> If both two predicates return false, evaluate the `:else` form. In -> this case, it returns y plus 40. If we use this function in the -> turtle app, we can keep our turtle between top and bottom of the frame. -{: ng-show="block62" .description} - > Reference: [Conditional `cond`](http://clojurebridge.github.io/community-docs/docs/clojure/cond/) {: ng-show="block62" .description} +```clojure +(if (= n 1) + "1st" + (if (= n 2) + "2nd" + (if (= n 3) + "3rd" + (str n "th")))) +``` + +In this case `cond` comes in handy. + ```clojure (cond - (> (+ y 40) 150) -150 - (< (+ y 40) -150) 150 - :else (+ y 40))) + (= n 1) "1st" + (= n 2) "2nd" + (= n 3) "3rd" + :else (str n "th")) ```
@@ -192,44 +192,75 @@ ng-click="block21=!block21"> predicate1 expression-to-evaluate-when-predicate1-is-true predicate2 expression-to-evaluate-when-predicate2-is-true ... - :else expression-to-evaluate-when-all-above-are-false) + :else expression-to-evaluate-when-all-above-are-false) +``` + + +
+#### `cond` example + +```clojure +(cond + (< x 10) "x is smaller than 10" + (< 10 x 20) "x is between 10 and 20" + (< 20 x 30) "x is between 20 and 30" + (< 30 x 40) "x is between 30 and 40" + :else "x is bigger than 40") ``` +
-#### EXERCISE 2: Y value within a frame - part 2 +#### EXERCISE 3 [BONUS]: Temperature conversion with `cond` {: .slide_title .slide} -> The function we wrote in the previous exercise, `y-within-frame`, has -> a flaw. If the given y value is -1000, the function will return -960. -> Since y value of the frame bottom is -150, -960 is beyond that. -> Your turtle will go invisible area. Let's make it real within-frame -> function using `cond`. +Write a function that can convert degrees Celcius, Fahrenheit, or Kelvin to Celcius -* Write a function `y-within-frame-cond` that takes y (vertical position) as an argument. -* You may use `cond` example in the slide. -* The function should return the y value between -150 and 150. +Here is how it should work - - See: [x and y in absolute values](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE.md#x-and-y-in-absolute-values) +``` clojure +(to-celcius 32.0 :F) ;=> 0.0 +(to-celcius 300 :K) ;=> 26.85 +(to-celcius 22.5 :C) ;=> 22.5 +(to-celcius 22.5 :gibberish) ;=> "Unknown scale: :gibberish" +``` -```clojure -;; usage of y-within-frame-cond function -(y-within-frame-cond 200) ;=> -150 -(y-within-frame-cond -200) ;=> 150 -(y-within-frame-cond 0) ;=> 40 +Starting point: + +``` clojure +(defn to-celcius [degrees scale] + (cond + ;; ... + )) ``` + +Formulas: + +* (°F - 32) x 5/9 = °C +* °K + 273.15 = °C
-#### EXERCISE 3 [BONUS]: Shoe Size Mapping +#### EXERCISE 3: Solution {: .slide_title .slide} -|Suppose you are traveling abroad..
(chart: www.jcpenney.com )| ![shoe size](img/shoe_size_chart_womens.png)| +Write a function that can convert degrees Celcius, Fahrenheit, or Kelvin to Celcius -1. pick up some of sets from the table, for example, us 6 and 9 -2. write mapping using `cond` (us 6 -> less than or equal to euro 36) -3. write a function, for example, `us-to-euro` with one argument -4. use `cond` you wrote at step 2 to complete the function +``` clojure +(defn to-celcius [degrees scale] + (cond + (= scale :C) degrees + (= scale :F) (* (- degrees 32) 5/9) + (= scale :K) (- degrees 273.15) + :else (str "Unknown scale: " scale))) +``` + +``` clojure +(to-celcius 32.0 :F) ;=> 0.0 +(to-celcius 300 :K) ;=> 26.85 +(to-celcius 22.5 :C) ;=> 22.5 +(to-celcius 22.5 :gibberish) ;=> "Unknown scale: :gibberish" +```
diff --git a/outline/functions.md b/outline/functions.md index 0be8738e..77954fa6 100644 --- a/outline/functions.md +++ b/outline/functions.md @@ -12,173 +12,62 @@ http://clojurebridge.github.io/curriculum/outline/functions.html {% endcomment %} -
+
Functions ------------------------------- {: .slide-title .chapter} * What are functions? -* Naming functions -* [bonus section] Functions that take other functions - - `map` and `reduce` -* [bonus section] Anonymous function -* [bonus section] Assignment: `let` +* Functions that take other functions +* Predicate functions +* Anonymous functions +* Pure functions
### What are functions? {: .slide_title .slide} -#### - -> You have already seen some functions, such as `count`, `conj`, -> `first`, and `rest`. All the arithmetic we did used functions, as -> well: `+`, `-`, `*`, and `/`. What does it mean to be a function, -> though? -{: ng-show="block11" .description} - -> A *function* is an independent, discrete piece of code that takes in -> some values (called *arguments*) and returns a value. -{: ng-show="block11" .description} - -> Reference: [Basics of Function](http://clojurebridge.github.io/community-docs/docs/clojure/function-creation/) -{: ng-show="block11" .description} - -* `count`, `conj`, `first` -* `+`, `-`, `*`, `/` +* You already know some: `count`, `conj`, `first` +* Maths operators are functions too: `+`, `-`, `*`, `/` * A piece of code that takes values and returns a value +* Reference: [Basics of Function](http://clojurebridge.github.io/community-docs/docs/clojure/function-creation/)
-#### An example function - -> * `defn` specifies that we are defining a function. -> * `forward-right` is the *name* of this function. -> * The string on the next line is the documentation for the function, which explains what the function does. This is optional. -> * `[turtle]` is the list of *arguments*. Here, we have one argument called `turtle`. -> * `(forward turtle 60) (right turtle 135)` is the *body* of the function. This is what executes when we use the function. +#### Defining functions + +> * We use `defn` to define a function. +> * We give it a *name* so we may call it later i.e. `add` +> * A Vector is used to specify the function's *arguments* i.e. `[x y]` +> * A String can be provided for a description e.g. `"Adds together..."` +> * The *body* is the form (thing in parentheses) that follows i.e. `(+ x y)` +> * We call the function by creating a form with it's name and arguments i.e. `(add 1 2)` {: ng-show="block21" .description} ```clojure -(defn forward-right - "Moves specified turtle forward and tilts its head" - [turtle] - (forward turtle 60) - (right turtle 135)) -``` -
- -
-#### How to use `forward-right` function - -> To use `forward-right`, we *call* the function, just like we've done with all the functions we've already used. -{: ng-show="block31" .description} - -```clojure -(forward-right :trinity) ;=> {:trinity {:angle 135}} -(forward-right :neo) ;=> {:neo {:angle 135}} -``` -
- -
-#### A function with multiple arguments +(defn add ; name + "Adds together two numbers" ; documentation + [x y] ; arguments + (+ x y)) ; body -> Functions can also take more than one argument. Let's make a -> `forward-right-with-len` function that takes a forward length, in addition -> to the turtle. -{: ng-show="block41" .description} - -```clojure -(defn forward-right-with-len - "Given turtle and length, forward the turtle and tilts its head" - [turtle len] - (forward turtle len) - (right turtle 135)) - -(forward-right-with-len :trinity 90) ;=> {:trinity {:angle 135}} -(forward-right-with-len :neo 80) ;=> {:neo {:angle 135}} +(add 1 2) ;=> 3 +(add (add 1 2) 4) ;=> 7 ```
-
-#### EXERCISE 1: Move turtles using function -{: .slide_title .slide} - -* Go to `walk.clj` -* Write a function, `forward-right` appeared in the slide. - -```clojure -(defn forward-right - "Moves specified turtle forward and tilts its head" - [turtle] - (forward turtle 60) - (right turtle 135)) -``` - -* On the last line of the function, hit Ctrl + - Enter or Cmd + Enter (no shift key) - to evaluate the function -* Write a line that uses the function, for example: `(forward-right :trinity)` -* Evaluate the line at least 8 times -
- -
-#### EXERCISE 2: Move turtles using function with parameters -{: .slide_title .slide} - -* Go to `walk.clj` -* Write a function, `forward-right-with-len-ang` that takes three - arguments, turtle, len, and angle (extension of `forward-right-with-len`) -* On the last line of the function, evaluate it by hitting Cmd + Enter - or Ctrl + Enter -* Write a line that uses the function, for example: - `(forward-right-with-len-ang :trinity 60 120)` -* Evaluate the line many times by hitting Cmd + Enter or Ctrl + Enter -
-
-### Naming functions +### EXERCISE: Find per-person share of bill among a group {: .slide_title .slide} -#### Names are Symbols - -> Function names are symbols, just like the symbols we used with `def` -> when assigning names to values. -{: ng-show="block61" .description} - -> Symbols have to begin with a non-numeric character, and they can -> contain alphanumeric characters, along with *, +, !, -, _, and ?. -> This flexibility is important with functions, as there are certain -> idioms we use. -{: ng-show="block61" .description} - -#### Two types of functions - -> Clojure has two type of functions: -> 1. function that returns a value, -> 2. function that returns true or false. -> The second type is called *predicate*s. -{: ng-show="block62" .description} - - -##### Predicate function examples - -> In Clojure, `=` is a predicate function, which may be a surprising -> fact. Other than that, like many other computer languages, -> Clojure has predicate functions to test greater than, less than or such. -> Mostly predicate functions end with `?`. -{: ng-show="block63" .description} - -> * `=`, `not=` -> * `>`, `<`, `>=`, `<=` -> * `true?`, `false?`, `empty?`, `nil?`, `vector?`, `map?` +* Create a new function, `add-one`, that takes a single argument + and adds one to it. +* It should call our `add` function.
-#### [Bonus section] - ### Functions that take other functions {: .slide_title .slide} @@ -186,9 +75,9 @@ Functions > Some of the most powerful functions you can use with collections can > take other functions as arguments. -> This is one of the most magical things about Clojure--and many other programming languages. -> That's a complicated idea, also, may not make sense at first. -> Let's look at an example and learn more about that. +> This is one of the most magical things about Clojure and many other programming languages. +> It's a complicated idea that may not make sense at first. +> Let's look at an example to learn more about it. {: ng-show="block71" .description} > Reference: [Higher-order Function](http://clojurebridge.github.io/community-docs/docs/clojure/higher-order-function/) @@ -208,13 +97,13 @@ Functions {: ng-show="block101" .description} ```clojure -(map name (turtle-names)) ;=> ("trinity" "neo" "oracle" "cypher") -(map (partial + 90) [0 30 60 90]) ;=> (90 120 150 180) +(map count ["a" "abc" "abcdefg"]) ;=> (1 3 7) +(map even? [0 1 2 3 4]) ;=> (true false true false true) ``` > References: -> [name](http://clojuredocs.org/clojure.core/name), -> [partial](http://clojuredocs.org/clojure.core/partial) +> [count](http://clojuredocs.org/clojure.core/count), +> [even?](http://clojuredocs.org/clojure.core/even_q)
@@ -235,26 +124,71 @@ Functions {: ng-show="block111" .description} ```clojure -(reduce str (turtle-names)) ;=> ":trinity:neo:oracle:cypher" -(reduce + [30 60 90]) ;=> 180 +(reduce + [30 60 90]) ;=> 180 +(reduce str ["h" "e" "l" "l" "o"]) ;=> "hello" ```
+
+### Bonus section +* Those are the main things you need to know about functions +* You can stop here and move on to the next stage in the curriculum +* But if you're thirsty for more, take a look at the bonus sections that follows +* You don't have to do all of these, go as far as you like +
+ +
-#### EXERCISE 3 [BONUS]: Find the average +#### EXERCISE: Find the average +{: .slide_title .slide} +* Create a function called `average` +* It should take a vector of bill amounts +* It should return the average of those amounts. +* Hint: You will need to use the functions `reduce` and `count`. +
+ +
+### Assignment: `let` {: .slide_title .slide} -* Create a function called `average` that takes a vector of maps. -* Use `[{:angle 30} {:angle 90} {:angle 50}]` as input. -* Calculate average value of :angle. +#### -* Hint: You will need to use the functions `map`, `reduce` and `count`. +> When you are creating functions, you may want to assign names to +> values in order to reuse those values or make your code more +> readable. Inside of a function, however, you should _not_ use `def`, +> like you would outside of a function. Instead, you should use a +> special form called `let`. +{: ng-show="block301" .description} + +> Reference: [Assignment let](http://clojurebridge.github.io/community-docs/docs/clojure/let/) +{: ng-show="block301" .description} +```clojure +(defn average [values] + (let [c (count values) + s (reduce + values)] + (/ s c))) +(average [1.0 1.0 2.0 3.0 5.0]) ;=> 2.4 +```
-#### [Bonus section] +### Predicate functions + +* Higher-order functions often just want to work with a yes/ no function +* Functions that return a boolean (true/ false) are often called *predicate functions* +* Predicate functions often end with a question mark +* You've already seen `even?` + +```clojure +(remove even? [1 2 3 4 5 6]) ;=> (1 3 5) + +(defn less-than-10? [x] (< x 10)) +(filter less-than-10? [8 9 10 11]) ;=> (8 9) +``` +
+
### Anonymous functions #### Functions without names @@ -290,7 +224,7 @@ Functions
-#### Anonymous function usage examples +#### Anonymous function example > Why would you ever need anonymous functions? > Anonymous functions can be very useful @@ -300,98 +234,48 @@ Functions {: ng-show="block203" .description} ```clojure -(map (fn [t] (forward t 45)) (turtle-names)) -;=> ({:trinity {:length 45}} {:neo {:length 45}} {:oracle {:length -45}} {:cypher {:length 45}}) - -(reduce (fn [x y] (+ x y)) [1 2 3]) ;=> 6 - -(reduce (fn [a b] (str a ", " b)) (map name (turtle-names))) -;=> "trinity, neo, oracle, cypher" +(filter (fn [x] (< x 10)) [8 9 10 11]) ;=> (8 9) ```
-#### [Bonus section] - -### Assignment: `let` -{: .slide_title .slide} +### Pure functions (inputs) -#### +* Where possible you should try to write *pure* functions +* To be pure a function must only depend upon it's inputs +* A pure function always returns the same output for a given input -> When you are creating functions, you may want to assign names to -> values in order to reuse those values or make your code more -> readable. Inside of a function, however, you should _not_ use `def`, -> like you would outside of a function. Instead, you should use a -> special form called `let`. -{: ng-show="block301" .description} +```clojure +(def one 1) +(defn add-one [x] (+ x one)) ; depends on `one` having been declared +(add-one 5) ;=> 6 +(def one 2) +(add-one 5) ;=> 7 oh dear :( +```
-#### Assigning names to values: `let` -{: .slide_title .slide} - -#### +#### Pure functions (side-effects) -> We can assign a name to value using `let` like `def`. -> When a name is assigned to a value, the name is called a *symbol*. -{: ng-show="block305" .description} - -> Reference: [Assignment let](http://clojurebridge.github.io/community-docs/docs/clojure/let/) -{: ng-show="block305" .description} +* It must also cause no observable side-effects +* A side effect is any result ```clojure -(let [mangoes 3 - oranges 5] - (+ mangoes oranges)) -;=> 8 +(println "I'm impure") ; writing to the console is a side-effect +(rand) ; reading (from a random number generator) is too ```
-#### `let` example - - - - - - -> This is the most complicated function we've seen so far, so let's go -> through each step. First, we have the name of the function, the -> documentation string, and the arguments, just as in other functions -{: ng-show="block311" .description} - -> Next, we see `let`. `let` takes a vector of alternating names and -> values. `t1` is the first name, and we assign the result of -> `(first names)` to it. We also assign the result of `(last names)` -> to `t2`. -{: ng-show="block312" .description} - -> After the vector of names and values, there is the body of the -> `let`. Just like a the body of a function, this executes and returns -> a value. Within the `let`, `t1` and `t2` are defined. -{: ng-show="block313" .description} - -> Go to `walk.clj` and write `opposite` function. -> Then, evaluate `opposite` function at the last line of the function definition. -> Also, evaluate usage example of `opposite` function. -{: ng-show="block314" .description} +#### Side-effects + +* Side-effects are vital if you want to interact with the real world! +* But they do make you functions less predictable (you can't rely on the real world)... +* ... and harder to reason about (so much to hold in your head)! -```clojure -;; function definition -(defn opposite - "Given a collection of turtle names, moves two of them in different directions." - [names] - (let [t1 (first names) - t2 (last names)] - (forward t1 40) - (backward t2 30))) - -;; function usage -(opposite (turtle-names)) -```
+ {% comment %} :star2: A link below is for a slide only. Go to [README.md](../README.md) diff --git a/outline/img/instarepl.png b/outline/img/instarepl.png deleted file mode 100644 index 75658a51..00000000 Binary files a/outline/img/instarepl.png and /dev/null differ diff --git a/outline/img/nightcode-click-import.png b/outline/img/nightcode-click-import.png new file mode 100644 index 00000000..7b272dbc Binary files /dev/null and b/outline/img/nightcode-click-import.png differ diff --git a/outline/img/nightcode-download.png b/outline/img/nightcode-download.png new file mode 100644 index 00000000..f1c67675 Binary files /dev/null and b/outline/img/nightcode-download.png differ diff --git a/outline/img/nightcode-open-project.png b/outline/img/nightcode-open-project.png new file mode 100644 index 00000000..c8ba7f4e Binary files /dev/null and b/outline/img/nightcode-open-project.png differ diff --git a/outline/img/nightcode-repl-reload.png b/outline/img/nightcode-repl-reload.png new file mode 100644 index 00000000..edc882d7 Binary files /dev/null and b/outline/img/nightcode-repl-reload.png differ diff --git a/outline/img/nightcode-repl-started.png b/outline/img/nightcode-repl-started.png new file mode 100644 index 00000000..8d998973 Binary files /dev/null and b/outline/img/nightcode-repl-started.png differ diff --git a/outline/img/nightcode-repl.png b/outline/img/nightcode-repl.png new file mode 100644 index 00000000..e4c67e38 Binary files /dev/null and b/outline/img/nightcode-repl.png differ diff --git a/outline/img/nightcode-startup.png b/outline/img/nightcode-startup.png new file mode 100644 index 00000000..585b77ee Binary files /dev/null and b/outline/img/nightcode-startup.png differ diff --git a/outline/img/nightcode-turtle-forward-40.png b/outline/img/nightcode-turtle-forward-40.png new file mode 100644 index 00000000..217722e5 Binary files /dev/null and b/outline/img/nightcode-turtle-forward-40.png differ diff --git a/outline/img/nightcode-turtle-walk-reload.png b/outline/img/nightcode-turtle-walk-reload.png new file mode 100644 index 00000000..585930a6 Binary files /dev/null and b/outline/img/nightcode-turtle-walk-reload.png differ diff --git a/outline/img/nightcode-turtle-walk.png b/outline/img/nightcode-turtle-walk.png new file mode 100644 index 00000000..4114f90a Binary files /dev/null and b/outline/img/nightcode-turtle-walk.png differ diff --git a/outline/img/nightcode-welcometoclojurebridge-core.png b/outline/img/nightcode-welcometoclojurebridge-core.png new file mode 100644 index 00000000..14565433 Binary files /dev/null and b/outline/img/nightcode-welcometoclojurebridge-core.png differ diff --git a/outline/img/nightcode-welcometoclojurebridge-run-with-repl.png b/outline/img/nightcode-welcometoclojurebridge-run-with-repl.png new file mode 100644 index 00000000..060864f2 Binary files /dev/null and b/outline/img/nightcode-welcometoclojurebridge-run-with-repl.png differ diff --git a/outline/img/repl.png b/outline/img/repl.png new file mode 100644 index 00000000..f0a49688 Binary files /dev/null and b/outline/img/repl.png differ diff --git a/outline/intro.md b/outline/intro.md index 391f827b..79627da9 100644 --- a/outline/intro.md +++ b/outline/intro.md @@ -113,9 +113,9 @@ Introduction to Programming with Clojure {: .slide_title .slide} ```clojure -(print-str "Hello, World!") (+ 3 4) -(forward :trinity 40) +(max 8 17 2) +(print-str "Hello, World!") ``` #### Parentheses @@ -132,19 +132,19 @@ Introduction to Programming with Clojure > Next to the parentheses, we see the instructions to the > computer. That instruction is normally what we call a _function_. > The functions do all the hard work in Clojure. -> `print-str`, `+` and `forward` are all functions. +> `+`, `max`, and `print-str` are all functions. > When these functions get run, they return a some type of value. > Clojure functions always return a value. {: ng-show="block32" .description} #### Arguments -> Many functions take in _arguments_--which are everything else inside -> the enclosing parentheses after the function--. -> `print-str` takes "Hello, World!" and returns a string. -> `+` takes 3 and 4, adds them, and returns 7. -> `forward` takes :trinity and 40, moves a turtle by 40 and returns -> the result. +> Many functions take in _arguments_ (everything else inside +> the enclosing parentheses function). +> +> * `+` takes 3 and 4, adds them, and returns 7. +> * `max` takes 8, 17, and 2, and returns the highest: 17. +> * `print-str` takes "Hello, World!" and prints it out. {: ng-show="block33" .description}
@@ -175,8 +175,9 @@ Introduction to Programming with Clojure ```clojure ;; example functions from a previous slide -(print-str "Hello, World!") ; a well-known hello world (+ 3 4) ; why not 3 + 4? figure out later +(max 8 17 2) ; there's a min too +(print-str "Hello, World!") ; a well-known hello world ```
@@ -195,7 +196,7 @@ Introduction to Programming with Clojure **R**ead, **E**val, **P**rint, **L**oop -![Instarepl](img/instarepl.png) +![Nightcode's repl](img/repl.png) @@ -203,49 +204,49 @@ Introduction to Programming with Clojure ## REPL in action {: .slide_title .slide} -#### Light Table's REPL -> Clojure has a REPL that you can run from the terminal easily, and -> we'll talk more about that later, but for now, let's use Light -> Table's REPL. It is a nice way to interact with Clojure from -> within Light Table. +#### Nightcode's REPL + +> To interact with Clojure, we're going to be using the REPL tab in +> Nightcode. It's a nice way to play with Clojure interactively. {: ng-show="block61" .description} -#### insta-REPL +#### Using the REPL -> Let's begin with "insta-REPL." -> Start Light Table, go to the "View" menu and click "Commands." -> Notice that typing ctrl+space is another handy way. -> Type "insta" and press enter when the "Instarepl: -> Open a Clojure instarepl" choice is highlighted. +> There's a couple of ways to get to a REPL in Nightcode. One general one +> that is always running in the corner of the window, and another that is +> launched with the "Run with REPL". {: ng-show="block62" .description} -> When you hit enter, you should see a message about "connecting" or -> "retrieving deps." Wait for the instarepl to finish connecting -> before typing anything. +> The easiest REPL to access and use is loaded from the beginning of +> opening Nightcode. You can find it in the bottom left hand window +> pane. {: ng-show="block62" .description} -#### Evaluate file and line +#### Evaluate program and line + + +> Nightcode also lets us evaluate a line or an entire program at a time. +> In the big panel, navigate to the `src/`(project_name)`/main.clj` file. +> After pressing "Run with REPL", you should see some output in the bottom +> pane. The first time you run this, it'll take a little while. +{: ng-show="block63" .description} -> Also, Light Table give us a way to evaluate Clojure program file and a -> single line of Clojure program. -> Open the file -> `welcometoclojurebridge/src/clojurebridge_turtle/walk.clj`. -> Hit Ctrl + Shift + Enter or -> Cmd + Shift + Enter to evaluate the -> file. Hit Ctrl + Enter or Cmd + -> Enter to evaluate each line. +> After this, you'll find a new REPL launch in that bottom pane. Here you +> can type commands just like the other REPL -- but now you can also type +> code in the main file, and run it with the `Eval` button +> (ctrl/cmd + shift + x, making sure the cursor is next to the code). {: ng-show="block63" .description}
-#### EXERCISE 1: Try insta-REPL +#### EXERCISE: Try the Clojure REPL -* Start Light Table -* Open instarepl -* Type Clojure functions below and see what happens +* Start Nightcode +* Focus on the REPL in the bottom left +* Type the Clojure functions below and see what happens ```clojure (print-str "Hello, World!") @@ -254,38 +255,28 @@ Introduction to Programming with Clojure (- 3 4) (* 3 4) ``` -> You might see an error in red while typing. This happens -> because Light Table is continually evaluating what you are typing, -> and before you finish, the code might not be valid. +> Make sure you type the lines exactly as you see them above, +> taking care to put the parentheses in the right locations.
#### EXERCISE 2: Evaluate file and line -* Open the file `welcometoclojurebridge/src/clojurebridge_turtle/walk.clj` -* Evaluate the entire file by hitting Cmd + Shift + Enter or Ctrl + - Shift + Enter and see what happens -* Type `(forward 40)` and evaluate this line by hitting Cmd + Enter or - Ctrl + Enter (no shift key) +* In NightCode, at the top left, click on "New Project" +* Choose a location and a name (nb: don't call it `quil`) +* Click on "Graphics" (the button with a big "Q" on it) +* Click on "Run with REPL", a window will pop up with a grey circle +* Find the line `(fill 192)` and change it to `(fill 250 20 20)` +* Select the code from lines 7 to 10 with your cursor (make sure all of it is selected) and click on `Eval Selection` (ctrl + E or cmd + E) * See what happens -* Type `(right 90)` or other commands and evaluate the lines one by - one by hitting Cmd + Enter or Ctrl + Enter (no shift key) -* Take a look [Turtles App API](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE.md) and -[How To Walk Turtles](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE-SAMPLES.md) -[section 1 and 2], and try more commands to walk your turtle
#### EXERCISE 3: Look at Clojure docs -* Go to either of `insta-REPL` or `walk.clj` file -* Move your cursor to the end of any function name, for example `+` -or `forward` -* Right click and select "Show docs" -* See the document appears on the Light Table -* Check your cursor is still at the end of the function name -* Right click and select "Show docs" -* See the document disappears +* In the REPL, try to look up the documentation for a function you have used +* You can use the `(clojure.repl/doc function-name)` command to do this. For instance, try typing `(clojure.repl/doc fill)` into the REPL +* You can also go to [ClojureDocs](http://clojuredocs.org) and look up docs online
{% comment %} diff --git a/outline/setup.md b/outline/setup.md index 23dd1d2c..39dd77c3 100644 --- a/outline/setup.md +++ b/outline/setup.md @@ -11,11 +11,10 @@ If anyone attending does not have access to a laptop running one of the above ch By the end of these instructions, you will have the following installed: -* **Java standard edition (SE)** - Clojure runs on top of Java. The Java Runtime Enviromment (JRE) is needed to run Clojure . -* **Leiningen** - a tool for running Clojure programs, also creating & managing Clojure projects -* **LightTable** - an easy to use development tool for Clojure and other programming languages -* **Git** - versioning your Clojure code (so you can go back to earlier versions if you make a mistake) - +* Java, a "virtual machine" that Clojure runs atop of +* Leiningen, a tool for running Clojure programs +* Nightcode, an editor for Clojure and other programming languages +* Git, a program for managing your program's code > Java version 1.8 (Java 8) is the latest version. Java 1.7 (Java 7) & 1.6 (Java 6) will also work. ## Instructions by operating system diff --git a/outline/setup_osx.md b/outline/setup_osx.md index f3ba90db..2d77af2f 100644 --- a/outline/setup_osx.md +++ b/outline/setup_osx.md @@ -6,11 +6,8 @@ OS X Setup * Configure Git * Make sure Java is installed * Install Leiningen -* Install Light Table +* Install Nightcode * Test your setup -* Troubleshooting - - OS X 10.6.8 - - Yosemite ## Starting a terminal @@ -94,32 +91,29 @@ Now run `which lein` and you should see the `lein` command. After you set up Leiningen as above, run the `lein version` command. This should take a while to run, as it will download some resources it needs the first time. If it completes successfully, you are golden! If not, ask an instructor for help. -## Install Light Table +## Install Nightcode -Go to the [Light Table site](http://www.lighttable.com/). On the page there, you should see a set of buttons that have download links for Light Table. Click the "OS X 10.7+" button and you will download a .zip file. +Go to the [Nightcode site](https://sekao.net/nightcode/). On the page there, you should see a link to download Nightcode, "Free Download(Version x.y.z)." Click the link and you will download a file, `nightcode-x.y.z-standalone.jar`. As of June 2016, the version is 1.3.1. -![Light Table downloads](img/light-table-download.png) -![Light Table downloads Mac](img/os_x/light-table-download.png) +![Nightcode downloads](img/nightcode-download.png) -There should now be a file named LightTableMac.zip in your Downloads folder. Double-click the file to unzip it, then move LightTable.app to your Applications folder. +Once the download finished, we want to start the editor. +To startup, go into your Downloads folder (or wherever you save files from your browser) and run the nightcode-x.y.z-standalone.jar file using `java` command. -The first time you launch Light Table you will be presented with a confirmation -prompt. Click "Open". -Light Table first-run dialog +Open a terminal and run the following commands: -### Opening files in Light Table from the command line *(optional)* - -Run the following commands to create a "shortcut command" called `light-table`: +```bash +cd ~/Downloads/ +java -jar nightcode-1.3.1-standalone.jar +``` - echo "alias light-table='open -a /Applications/LightTable/LightTable.app'" >> ~/.bash_profile - source ~/.bash_profile +![Nightcode](img/nightcode-startup.png) -You can now open files and folders in Light Table from the command line by entering `light-table path/to/the/file/you/want/to/open.clj`. ## Test your setup -You have set up Java, Leiningen, Light Table, and Git on your computer--all the tools you will need for this workshop. Before starting, we need to test them out. +You have set up Java, Leiningen, Nightcode, and Git on your computer--all the tools you will need for this workshop. Before starting, we need to test them out. #### Cloning out github repository @@ -156,51 +150,70 @@ This could take a long time, and will download many other pieces of code apps re This is starting a REPL, which we will learn about soon. It's a special terminal for Clojure. At the REPL prompt, type `(+ 1 1)` and press Return. Did you get the answer `2` back? You will learn more about that in the course. For now, press the Control button and D button on your keyboard together (abbreviated as Ctrl+D). This should take you out of the Clojure REPL and back to your normal terminal prompt. Then, the terminal will show you the following message: `user=> Bye for now!` -#### Testing Light Table +#### Testing Nightcode + +If Nightcode isn't started yet or closed, open it by typing the command on terminal: + +```bash +java -jar nightcode-1.3.1-standalone.jar +``` + +At the bottom left of the screen, type `(+ 1 1)` into the window. It should look like the following image: + +Testing Nightcode + +If you see the result, 2, that worked, great! -Now we will open and run the sample Clojure apps in Light Table. Start LightTable from Applications > LightTable. -In Light Table, click on the menu "File" then choose "Open Folder." Find the -directory, `welcometoclojurebridge`, which was created when you ran -`git clone` command. Click "Upload." In the workspace menu on the -left, click on `welcometoclojurebridge` - `src` - -`welcometoclojurebridge` - `core.clj`. Double-click the `core.clj` file -to open it. This is a Clojure program. +#### Testing apps -![Testing apps - welcome code](img/testing-welcome-app-code.png) +Now we will open and run the sample Clojure apps in Nightcode. +On the top left corner, click "Import" then find the directory, +`welcometoclojurebridge`, which was created when you ran +`git clone` command. Click "Open." +In the project directory tree on the left, click on `src` - `welcometoclojurebridge` - `core.clj`. The `core.clj` file will be opened on the right side. +This is a Clojure program. -Click on the file contents and -press the following key combination: +Testing apps - click import +Testing apps - open welcometoclojurebridge +![Testing apps - core.clj](img/nightcode-welcometoclojurebridge-core.png) + +The next step is to run the code shown in the window. +Click "Run with REPL" on the bottom of the right side. +It may take a while. +Eventually, repl will start and show a prompt on the bottom of the window. +Once, you see the prompt, click "Reload" button. + + +![Testing apps - start repl](img/nightcode-welcometoclojurebridge-run-with-repl.png) +![Testing apps - repl started](img/nightcode-repl-started.png) +![Testing apps - repl reload](img/nightcode-repl-reload.png) -Cmd + Shift + Enter You should see a fun welcome message. ![Testing apps - welcome](img/testing-welcomeclojurebridge.png) -Next, in the workspace menu on the left, click on +Let's try one more sample. +In the directory tree on the left, click on `welcometoclojurebridge` - `src` - `clojurebridge-turtle` - -`walk.clj`. Double-click the core.clj file to open it. - -![Testing apps - walk code](img/testing-turtle-walk-code.png) - -press the following key combination: +`walk.clj`. The `walk.clj` file will open on the right side. +Like we did before, click "Reload" button. -Cmd + Shift + Enter +![Testing apps - walk code](img/nightcode-turtle-walk.png) +![Testing apps - walk reload](img/nightcode-turtle-walk-reload.png) -An initial image of the turtles app will pop up. -Type `(forward 40)` at the end of the `walk.clj` and press the -following combination: +An initial image of the turtles app should pop up. +A small triangle on the center is the *turtle*. -Cmd + Enter -You should see this on the Light Table: +Type `(forward 40)` on the repl at the bottom of the window. +You should see the turtle moved upword: -![Testing apps - forward](img/testing-turtle-forward.png) +![Testing apps - forward](img/nightcode-turtle-forward-40.png) -also, your turtle should move. #### Success! @@ -241,21 +254,6 @@ To not have lines wrap around if they are to long for the screen: * Type `user behaviors` and click the proposed command * This open a file that you can edit to add `[:editor :lt.objs.editor/no-wrap]` -## Troubleshooting - -### OS X 10.6.8 - -Light Table actually does work on OS X 10.6.8. It thinks it does not. To convince it otherwise, do this: - - 1. Use a text editor to open /Applications/LightTable.app/Contents/Info.plist - 2. Search for the key LSMinimumSystemVersion - 3. Remove that key from the file. Delete this entire text: LSMinimumSystemVersion 10.7.5 - 4. Save the file, and you should be able to start Light Table. - -### Yosemite - -Yosemite was released after Light Table development was stalled. -Because of this historical reason, students may encounter troubles to start or use Light Table on Yosemite. -In such a case, [Nightcode](https://sekao.net/nightcode/) is another option. -See the instruction, -[Getting Started with Clojure using Nightcode](https://github.com/ClojureBridge/getting-started/blob/master/nightcode.md). +If you want to know what the turtle (*a small triangle*) can do, +see [Turtle App API](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE.md) and +[How to Walk Turtles](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE-SAMPLES.md) for more information. \ No newline at end of file diff --git a/outline/setup_ubuntu.md b/outline/setup_ubuntu.md index a1a74cb3..75648254 100644 --- a/outline/setup_ubuntu.md +++ b/outline/setup_ubuntu.md @@ -6,7 +6,7 @@ Ubuntu Setup * Configure Git * Make sure Java is installed * Install Leiningen -* Install Light Table +* Install Nightcode * Test your setup ## Starting a terminal @@ -27,7 +27,7 @@ See if you already have Git installed with `git version`. If the `git` command is not found, install it with this command in the terminal: ```bash -sudo apt-get install git` +sudo apt-get install git ``` ## Configure Git @@ -87,42 +87,28 @@ export PATH=$PATH:/usr/local/bin After you run the above commands, run the `lein version` command. It should take a while to run, as it will download some resources it needs the first time. If it completes successfully, you are golden! If not, ask an instructor for help. -## Install Light Table +## Install Nightcode -LightTable is only available for 64-bit version of Ubuntu (or you can [build it from source](https://github.com/LightTable/LightTable) for 32-bit Linux). To find out if you have 64-bit Ubuntu, click Dash Home and type Details. You should see a window like this: +Go to the [Nightcode site](https://sekao.net/nightcode/). On the page there, you should see a link to download Nightcode, "Free Download(Version x.y.z)." Click the link and you will download a file, `nightcode-x.y.z-standalone.jar`. As of June 2016, the version is 1.3.1. -![Ubuntu Version](img/ubuntu/ubuntu-version.png) +![Nightcode downloads](img/nightcode-download.png) -Alternatively, open your terminal and type `uname -m` if the output says "x86_64" you have a 64-bit OS, if it says "i686" you have a 32-bit OS. +Once the download finished, we want to start the editor. +To startup, go into your Downloads folder (or wherever you save files from your browser) and run the nightcode-x.y.z-standalone.jar file using `java` command. -Go to the [Light Table site](http://www.lighttable.com/) and click the "Linux64" button and select the "Save file". +Open a terminal and run the following commands: -![Light Table downloads](img/light-table-download.png) -![Light Table downloads Ubuntu](img/ubuntu/light-table-download.png) - -Open up your terminal and cd to the directory where your downloads go `cd ~/Downloads`. -Check to see that your file is there. `ls` -Extract the compressed file `tar -xzf LightTableLinux64.tar.gz` -Check to see that there is now a directory called LightTable `ls` -Move the LightTable directory to "/usr/local/bin" `sudo mv LightTable /usr/local/bin` -Set your path so you can launch LightTable from the command line `export PATH=$PATH:/usr/local/bin/LightTable` -Launch LightTable `LightTable` - -If you want, you can create a launcher for Light Table. `sudo gnome-desktop-item-edit /usr/share/applications/ --create-new` -You should see a window like this: - -![Create Icon](img/ubuntu/create_icon.png) - -Name the launcher LightTable. Type the path to the command `/usr/local/bin/LightTable/LightTable`. Click the icon. The LightTable icon can be found at `/usr/local/bin/LightTable/core/img/lticon.png`. - -### Opening files in Light Table from the command line *(optional)* +```bash +cd ~/Downloads/ +java -jar nightcode-1.3.1-standalone.jar +``` -If you'd prefer, you can open files/folders in LightTable from the command line by typing `light-table /path/to/the/file/you/want/to/open.clj`. +![Nightcode](img/nightcode-startup.png) ## Testing your setup -You have set up Java, Leiningen, Light Table, and Git on your computer--all the tools you will need for this course. Before starting, we need to test them out. +You have set up Java, Leiningen, Nightcode, and Git on your computer--all the tools you will need for this course. Before starting, we need to test them out. #### Cloning out github repository @@ -163,52 +149,70 @@ button on your keyboard together (abbreviated as Ctrl+D). This should take you out of the Clojure REPL and back to your normal terminal prompt. Then, the terminal will show you the following message: `user=> Bye for now!` -#### Testing Light Table +#### Testing Nightcode + +If Nightcode isn't started yet or closed, open it by typing the command on terminal: -Now we will open and run the sample Clojure apps in Light Table, so start Light Table +```bash +java -jar nightcode-1.3.1-standalone.jar +``` -In Light Table, click on the menu "File" then choose "Open Folder." Find the -directory, `welcometoclojurebridge`, which was created when you ran -`git clone` command. Click "Upload." In the workspace menu on the -left, click on `welcometoclojurebridge` - `src` - -`welcometoclojurebridge` - `core.clj`. Double-click the `core.clj` file -to open it. This is a Clojure program. +At the bottom left of the screen, type `(+ 1 1)` into the window. It should look like the following image: -![Testing apps - welcome code](img/testing-welcome-app-code.png) +Testing Nightcode +If you see the result, 2, that worked, great! -Click on the file contents and -press the following key combination: -Ctrl + Shift + Enter +### Testing apps + +Now we will open and run the sample Clojure apps in Nightcode. +On the top left corner, click "Import" then find the directory, +`welcometoclojurebridge`, which was created when you ran +`git clone` command. Click "Open." +In the project directory tree on the left, click on `src` - `welcometoclojurebridge` - `core.clj`. The `core.clj` file will be opened on the right side. +This is a Clojure program. + +Testing apps - click import +Testing apps - open welcometoclojurebridge +![Testing apps - core.clj](img/nightcode-welcometoclojurebridge-core.png) + +The next step is to run the code shown in the window. +Click "Run with REPL" on the bottom of the right side. +It may take a while. +Eventually, repl will start and show a prompt on the bottom of the window. +Once, you see the prompt, click "Reload" button. + + +![Testing apps - start repl](img/nightcode-welcometoclojurebridge-run-with-repl.png) +![Testing apps - repl started](img/nightcode-repl-started.png) +![Testing apps - repl reload](img/nightcode-repl-reload.png) + You should see a fun welcome message. ![Testing apps - welcome](img/testing-welcomeclojurebridge.png) -Next, in the workspace menu on the left, click on +Let's try one more sample. +In the directory tree on the left, click on `welcometoclojurebridge` - `src` - `clojurebridge-turtle` - -`walk.clj`. Double-click the core.clj file to open it. - -![Testing apps - walk code](img/testing-turtle-walk-code.png) +`walk.clj`. The `walk.clj` file will open on the right side. +Like we did before, click "Reload" button. -press the following key combination: +![Testing apps - walk code](img/nightcode-turtle-walk.png) +![Testing apps - walk reload](img/nightcode-turtle-walk-reload.png) -Ctrl + Shift + Enter -An initial image of the turtles app will pop up. +An initial image of the turtles app should pop up. +A small triangle on the center is the *turtle*. -Type `(forward 40)` at the end of the `walk.clj` and press the -following combination: -Ctrl + Enter +Type `(forward 40)` on the repl at the bottom of the window. +You should see the turtle moved upword: -You should see this on the Light Table: +![Testing apps - forward](img/nightcode-turtle-forward-40.png) -![Testing apps - forward](img/testing-turtle-forward.png) - -also, your turtle should move. > Pressing the Control button and Space Bar together (abbreviated `Ctrl+Space`) is how you start giving Light Table a command. @@ -217,3 +221,7 @@ also, your turtle should move. Congratulations! You have opened and run your first Clojure apps, and your install and setup are all completed! + +If you want to know what the turtle (*a small triangle*) can do, +see [Turtle App API](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE.md) and +[How to Walk Turtles](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE-SAMPLES.md) for more information. \ No newline at end of file diff --git a/outline/setup_win7.md b/outline/setup_win7.md index c02928b0..89dacbf5 100644 --- a/outline/setup_win7.md +++ b/outline/setup_win7.md @@ -6,7 +6,7 @@ Windows 7 Setup * Configure Git * Install Java * Install Leiningen -* Install Light Table +* Install Nightcode * Test your setup * Troubleshooting @@ -94,28 +94,33 @@ Leiningen is a tool used on the command line to manage Clojure projects. Next, go back to [the Leiningen Windows installer site](http://leiningen-win-installer.djpowell.net/) and download the file linked as "leiningen-win-installer." Run this executable and follow the "Detailed installation" section at the Leiningen Windows Installer site. At the end of the installation, leave "Run a Clojure REPL" checked before you click "Finish." If a terminal window opens that looks like the one on the Leiningen Windows installer site, then you are good to go. -## Install Light Table +## Install Nightcode -Go to the [Light Table site](http://www.lighttable.com/). On the page there, you should see a set of buttons that have download links for Light Table. Click the "Win" button and you will download a .zip file. +Go to the [Nightcode site](https://sekao.net/nightcode/). On the page there, you should see a link to download Nightcode, "Free Download(Version x.y.z)." Click the link and you will download a file, `nightcode-x.y.z-standalone.jar`. As of June 2016, the version is 1.3.1. -![Light Table downloads](img/light-table-download.png) -![Light Table downloads Windows](img/win/light-table-download.png) +![Nightcode downloads](img/nightcode-download.png) -Unzip this file (either by finding it in your Downloads folder and -double-clicking it, or by choosing "Open" when downloading.) Inside -the .zip file, there is a a directory called "Light Table". Drag this -to your desktop, or another location of your choosing. Be sure the -location you choose does not have spaces anywhere in the file path. +Once the download finished, we want to start the editor. +To startup, go into your Downloads folder (or wherever you save files from your browser) and run the nightcode-x.y.z-standalone.jar file using `java` command. + + +Open a command propt window and type following commands + +```bash +cd Downloads +java -jar nightcode-1.3.1-standalone.jar +``` + +![Nightcode](img/nightcode-startup.png) -Inside the Light Table directory, there is an application called Light Table. Right-click it and choose "Pin to Start Menu" so you can start it more quickly. ## Test your setup -You have set up Java, Leiningen, Light Table, and Git on your computer--all the tools you will need for this workshop. Before starting, we need to test them out. +You have set up Java, Leiningen, Nightcode, and Git on your computer--all the tools you will need for this workshop. Before starting, we need to test them out. #### Cloning out github repository -Go to your command prompt windoe and run the following command: +Go to your command prompt window and run the following command: ```bash git clone https://github.com/ClojureBridge/welcometoclojurebridge @@ -150,51 +155,69 @@ button on your keyboard together (abbreviated as Ctrl+D). This should take you out of the Clojure REPL and back to your normal command prompt. Then, the command prompt will show you the following message: `user=> Bye for now!` -#### Testing Light Table -Now we will open and run the sample Clojure apps in Light Table, so start Light Table. +#### Testing Nightcode -In Light Table, click on the menu "File" then choose "Open Folder." Find the -directory, `welcometoclojurebridge`, which was created when you ran -`git clone` command. Click "Upload." In the workspace menu on the -left, click on `welcometoclojurebridge` - `src` - -`welcometoclojurebridge` - `core.clj`. Double-click the `core.clj` file -to open it. This is a Clojure program. +If Nightcode isn't started yet or closed, open it by typing the command on terminal: -![Testing apps - welcome code](img/testing-welcome-app-code.png) +```bash +java -jar nightcode-1.3.1-standalone.jar +``` -Click on the file contents and -press the following key combination: +At the bottom left of the screen, type `(+ 1 1)` into the window. It should look like the following image: -Ctrl + Shift + Enter +Testing Nightcode -You should see a fun welcome message. +If you see the result, 2, that worked, great! -![Testing apps - welcome](img/testing-welcomeclojurebridge.png) +#### Testing apps +Now we will open and run the sample Clojure apps in Nightcode. +On the top left corner, click "Import" then find the directory, +`welcometoclojurebridge`, which was created when you ran +`git clone` command. Click "Open." +In the project folder tree on the left, click on `src` - `welcometoclojurebridge` - `core.clj`. The `core.clj` file will be opened on the right side. +This is a Clojure program. -Next, in the workspace menu on the left, click on -`welcometoclojurebridge` - `src` - `clojurebridge-turtle` - -`walk.clj`. Double-click the core.clj file to open it. +Testing apps - click import +Testing apps - open welcometoclojurebridge +![Testing apps - core.clj](img/nightcode-welcometoclojurebridge-core.png) + + +The next step is to run the code shown in the window. +Click "Run with REPL" on the bottom of the right side. +It may take a while. +Eventually, repl will start and show a prompt on the bottom of the window. +Once, you see the prompt, click "Reload" button. + + +![Testing apps - start repl](img/nightcode-welcometoclojurebridge-run-with-repl.png) +![Testing apps - repl started](img/nightcode-repl-started.png) +![Testing apps - repl reload](img/nightcode-repl-reload.png) -![Testing apps - walk code](img/testing-turtle-walk-code.png) -press the following key combination: +You should see a fun welcome message. -Ctrl + Shift + Enter +![Testing apps - welcome](img/testing-welcomeclojurebridge.png) -An initial image of the turtles app will pop up. -Type `(forward 40)` at the end of the `walk.clj` and press the -following combination: +Let's try one more sample. +In the directory tree on the left, click on +`welcometoclojurebridge` - `src` - `clojurebridge-turtle` - +`walk.clj`. The `walk.clj` file will open on the right side. +Like we did before, click "Reload" button. -Ctrl + Enter +![Testing apps - walk code](img/nightcode-turtle-walk.png) +![Testing apps - walk reload](img/nightcode-turtle-walk-reload.png) -You should see this on the Light Table: +An initial image of the turtles app should pop up. +A small triangle on the center is the *turtle*. -![Testing apps - forward](img/testing-turtle-forward.png) -also, your turtle should move. +Type `(forward 40)` on the repl at the bottom of the window. +You should see the turtle moved upword: + +![Testing apps - forward](img/nightcode-turtle-forward-40.png) > press the Control button and Space Bar together (abbreviated Ctrl+Space). This is how you start giving Light Table a command @@ -203,6 +226,10 @@ also, your turtle should move. Congratulations! You have opened and run your first Clojure apps, and your install and setup are all completed! +If you want to know what the turtle (*a small triangle*) can do, +see [Turtle App API](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE.md) and +[How to Walk Turtles](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE-SAMPLES.md) for more information. + ## Troubleshooting diff --git a/outline/setup_win8.md b/outline/setup_win8.md index 8807ca77..c68095e7 100644 --- a/outline/setup_win8.md +++ b/outline/setup_win8.md @@ -6,7 +6,7 @@ Windows 8 Setup * Configure Git * Install Java * Install Leiningen -* Install Light Table +* Install Nightcode * Test your setup * Troubleshooting @@ -99,21 +99,31 @@ Leiningen is a tool used on the command line to manage Clojure projects. Next, go back to [the Leiningen Windows installer site](http://leiningen-win-installer.djpowell.net/) and download the file linked as "leiningen-win-installer." Run this executable and follow the "Detailed installation" section at the Leiningen Windows Installer site. At the end of the installation, leave "Run a Clojure REPL" checked before you click "Finish." If a terminal window opens that looks like the one on the Leiningen Windows installer site, then you are good to go. -## Install Light Table -Go to the [Light Table site](http://www.lighttable.com/). On the page there, you should see a set of buttons that have download links for Light Table. Click the "Win" button and you will download a .zip file. +## Install Nightcode -![Light Table downloads](img/light-table-download.png) -![Light Table downloads Windows](img/win/light-table-download.png) +Go to the [Nightcode site](https://sekao.net/nightcode/). On the page there, you should see a link to download Nightcode, "Free Download(Version x.y.z)." Click the link and you will download a file, `nightcode-x.y.z-standalone.jar`. As of June 2016, the version is 1.3.1. -Unzip this file (either by finding it in your Downloads folder and double-clicking it, or by choosing "Open" when downloading.) Inside the .zip file, there is a a directory called "Light Table". Drag this to your desktop. (If you know what you are doing and want this somewhere else, that is fine.) +![Nightcode downloads](img/nightcode-download.png) -Inside the Light Table directory, there is an application called Light Table. Right-click it and choose "Pin to Start Menu" so you can start it more quickly. +Once the download finished, we want to start the editor. +To startup, go into your Downloads folder (or wherever you save files from your browser) and run the nightcode-x.y.z-standalone.jar file using `java` command. + + +Open a command prompt and run the following commands: + +```bash +cd ~/Downloads/ +java -jar nightcode-1.3.1-standalone.jar +``` + +![Nightcode](img/nightcode-startup.png) ## Test your setup -You have set up Java, Leiningen, Light Table, and Git on your computer--all the tools you will need for this workshop. Before starting, we need to test them out. +You have set up Java, Leiningen, Nightcode, and Git on your computer--all the tools you will need for this workshop. Before starting, we need to test them out. + #### Cloning out github repository @@ -141,7 +151,7 @@ This will take you to the folder with the source code. After that completes, run lein repl ``` -This could take a long time, and will download many other pieces of code it relies on. You should see lines that start with `Retrieving ...` on your screen. When it finishes, your terminal should look like the following: +This could take a long time, and will download many other pieces of code it relies on. You should see lines that start with `Retrieving ...` on your screen. When it finishes, your command propmpt should look like the following: ![Testing lein repl](img/win/testing-lein-repl.png) @@ -153,51 +163,71 @@ button on your keyboard together (abbreviated as Ctrl+D). This should take you out of the Clojure REPL and back to your normal command prompt. Then, the command prompt will show you the following message: `user=> Bye for now!` -#### Testing Light Table +#### Testing Nightcode -Now we will open and run the sample Clojure apps in Light Table, so start Light Table. +If Nightcode isn't started yet or closed, open it by typing the command on the command propmt: -In Light Table, click on the menu "File" then choose "Open Folder." Find the -directory, `welcometoclojurebridge`, which was created when you ran -`git clone` command. Click "Upload." In the workspace menu on the -left, click on `welcometoclojurebridge` - `src` - -`welcometoclojurebridge` - `core.clj`. Double-click the `core.clj` file -to open it. This is a Clojure program. +```bash +java -jar nightcode-1.3.1-standalone.jar +``` -![Testing apps - welcome code](img/testing-welcome-app-code.png) +At the bottom left of the screen, type `(+ 1 1)` into the window. It should look like the following image: -Click on the file contents and -press the following key combination: +Testing Nightcode -Ctrl + Shift + Enter +If you see the result, 2, that worked, great! -You should see a fun welcome message. -![Testing apps - welcome](img/testing-welcomeclojurebridge.png) +#### Testing apps +Now we will open and run the sample Clojure apps in Nightcode. +On the top left corner, click "Import" then find the directory, +`welcometoclojurebridge`, which was created when you ran +`git clone` command. Click "Open." +In the project directory tree on the left, click on `src` - `welcometoclojurebridge` - `core.clj`. The `core.clj` file will be opened on the right side. +This is a Clojure program. -Next, in the workspace menu on the left, click on -`welcometoclojurebridge` - `src` - `clojurebridge-turtle` - -`walk.clj`. Double-click the core.clj file to open it. -![Testing apps - walk code](img/testing-turtle-walk-code.png) +Testing apps - click import +Testing apps - open welcometoclojurebridge +![Testing apps - core.clj](img/nightcode-welcometoclojurebridge-core.png) -press the following key combination: -Ctrl + Shift + Enter +The next step is to run the code shown in the window. +Click "Run with REPL" on the bottom of the right side. +It may take a while. +Eventually, repl will start and show a prompt on the bottom of the window. +Once, you see the prompt, click "Reload" button. -An initial image of the turtles app will pop up. -Type `(forward 40)` at the end of the `walk.clj` and press the -following combination: +![Testing apps - start repl](img/nightcode-welcometoclojurebridge-run-with-repl.png) +![Testing apps - repl started](img/nightcode-repl-started.png) +![Testing apps - repl reload](img/nightcode-repl-reload.png) -Ctrl + Enter -You should see this on the Light Table: +You should see a fun welcome message. -![Testing apps - forward](img/testing-turtle-forward.png) +![Testing apps - welcome](img/testing-welcomeclojurebridge.png) + + +Let's try one more sample. +In the directory tree on the left, click on +`welcometoclojurebridge` - `src` - `clojurebridge-turtle` - +`walk.clj`. The `walk.clj` file will open on the right side. +Like we did before, click "Reload" button. + +![Testing apps - walk code](img/nightcode-turtle-walk.png) +![Testing apps - walk reload](img/nightcode-turtle-walk-reload.png) + +An initial image of the turtles app should pop up. +A small triangle on the center is the *turtle*. + + +Type `(forward 40)` on the repl at the bottom of the window. +You should see the turtle moved upword: + +![Testing apps - forward](img/nightcode-turtle-forward-40.png) -also, your turtle should move. > press the Control button and Space Bar together (abbreviated Ctrl+Space). This is how you start giving Light Table a command @@ -207,11 +237,12 @@ Congratulations! You have opened and run your first Clojure apps, and your install and setup are all completed! -### Troubleshooting +If you want to know what the turtle (*a small triangle*) can do, +see [Turtle App API](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE.md) and +[How to Walk Turtles](https://github.com/ClojureBridge/welcometoclojurebridge/blob/master/outline/TURTLE-SAMPLES.md) for more information. + -* If you receive errors while running Light Table about Java or JDK, - these may be resolved by finishing the installation of Leiningen - first. If not, see a TA to look at your environment variables. +### Troubleshooting * Leiningen Windows Installer has an issue that it doesn't install lein.bat correctly. This causes curl.exe to fail downloading files diff --git a/outline/simple_values.md b/outline/simple_values.md index e86560d9..7b214675 100644 --- a/outline/simple_values.md +++ b/outline/simple_values.md @@ -37,79 +37,6 @@ Simple Values {: ng-show="block71" .description} -
-### Strings -{: .slide_title .slide} - -#### - -> What is a string? A string is just a piece of text. To make a -> string, you enclose it in quotation marks. -> Look at the last example. A backslash is how we put a quotation mark -> inside a string. Do not try using single quotes to make a string. -{: ng-show="block21" .description} - -> Reference: [String](http://clojurebridge.github.io/community-docs/docs/clojure/string/) -{: ng-show="block21" .description} - -```clojure -"Hello, World!" -"This is a longer string that I wrote for purposes of an example." -"Aubrey said, \"I think we should go to the Orange Julius.\"" -``` -
- -
-### Booleans and nil -{: .slide_title .slide} - -#### - ->A boolean is a true or false value, and you type them just like that, ->`true` and `false`. Often in programming, we need to ask a true or ->false question, like "Is this class in the current semester?" or "Is ->this person's birthday today?" When we ask those questions, we get a ->boolean back. -{: ng-show="block31" .description} - -> There is another value `nil`, which behaves like a boolean in terms -> of __truthiness__. -> But, `nil` means no value at all and not a boolean -{: ng-show="block31" .description} - -> Reference: [Truthiness](http://clojurebridge.github.io/community-docs/docs/clojure/truthiness/) -{: ng-show="block31" .description} - - -```clojure -true -false -nil -``` -
- -
-### Keywords -{: .slide_title .slide} - -#### - -> Keywords are the strangest of the basic value types. Some computer -> languages have similar one. However, keywords don’t have a real -> world analog like numbers, strings, or booleans. -> You can think of them as a special type of string, one that’s used for -> labels. They are often used as keys of key-value pair for maps (data -> structure; will learn later). -{: ng-show="block41" .description} - - -```clojure -:trinity -:first -:last -``` -
-
### Numbers @@ -207,7 +134,7 @@ Prefix: (+ (- (+ (+ 1 (/ (* 2 3) 4)) 5) (/ (* 6 7) 8)) 9)
-### Why prefix is better? +### The benefits of prefix notation #### Explicit precedence @@ -254,6 +181,78 @@ Prefix: (+ 1 2 3 4 5 6 7 8 9) ```
+
+### Strings +{: .slide_title .slide} + +#### + +> What is a string? A string is just a piece of text. To make a +> string, you enclose it in quotation marks. +> Look at the last example. A backslash is how we put a quotation mark +> inside a string. Do not try using single quotes to make a string. +{: ng-show="block21" .description} + +> Reference: [String](http://clojurebridge.github.io/community-docs/docs/clojure/string/) +{: ng-show="block21" .description} + +```clojure +"Hello, World!" +"This is a longer string that I wrote for purposes of an example." +"Aubrey said, \"I think we should go to the Orange Julius.\"" +``` +
+ +
+### Booleans and nil +{: .slide_title .slide} + +#### + +>A boolean is a true or false value, and you type them just like that, +>`true` and `false`. Often in programming, we need to ask a true or +>false question, like "Is this class in the current semester?" or "Is +>this person's birthday today?" When we ask those questions, we get a +>boolean back. +{: ng-show="block31" .description} + +> There is another value `nil`, which behaves like a boolean in terms +> of __truthiness__. +> But, `nil` means no value at all and not a boolean +{: ng-show="block31" .description} + +> Reference: [Truthiness](http://clojurebridge.github.io/community-docs/docs/clojure/truthiness/) +{: ng-show="block31" .description} + + +```clojure +true +false +nil +``` +
+ +
+### Keywords +{: .slide_title .slide} + +#### + +> Keywords are the strangest of the basic value types. Some computer +> languages have similar one. However, keywords don’t have a real +> world analog like numbers, strings, or booleans. +> You can think of them as a special type of string, one that’s used for +> labels. They are often used as keys of key-value pair for maps (data +> structure; will learn later). +{: ng-show="block41" .description} + + +```clojure +:forename +:surname +:date-of-birth +``` +
## Assignment: `def` @@ -305,16 +304,15 @@ average-fruit-amount
#### EXERCISE 1: Basic arithmetic -* Take your height in feet and inches and convert it to inches using arithmetic in Clojure. -* Then convert that to centimeters. There are 2.54 centimeters in an inch. -* Lastly, ask two people near you for their height in centimeters. Find the average of your heights. +* How many minutes have elapsed since you arrived at the workshop today? +* Convert this value from minutes to seconds.
-#### EXERCISE 2 [BONUS]: Convert back to feet and inches +#### EXERCISE 2 [BONUS]: Minutes and seconds -* Convert that average back to feet and inches. -* The feet and the inches will be separate numbers. +* Convert 1000 seconds to minutes and seconds. +* The minutes and the seconds will be separate numbers. * `(quot x y)` will give you the whole number part of x divided by y. * `(rem x y)` will give you the remainder of x divided by y.