Created
June 8, 2012 04:09
-
-
Save hhutch/2893517 to your computer and use it in GitHub Desktop.
Clojure Slides - JVM Languages - Philly Coders - June 6, 2012
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="iso-8859-1"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" | |
lang="en" xml:lang="en"> | |
<head> | |
<title>Clojure</title> | |
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/> | |
<meta name="generator" content="Org-mode"/> | |
<meta name="generated" content="2012-06-07 23:17:36 EDT"/> | |
<meta name="author" content=""/> | |
<meta name="description" content=""/> | |
<meta name="keywords" content=""/> | |
<style type="text/css"> | |
<!--/*--><![CDATA[/*><!--*/ | |
html { font-family: Times, serif; font-size: 12pt; } | |
.title { text-align: center; } | |
.todo { color: red; } | |
.done { color: green; } | |
.tag { background-color: #add8e6; font-weight:normal } | |
.target { } | |
.timestamp { color: #bebebe; } | |
.timestamp-kwd { color: #5f9ea0; } | |
p.verse { margin-left: 3% } | |
pre { | |
border: 1pt solid #AEBDCC; | |
background-color: #F3F5F7; | |
padding: 5pt; | |
font-family: courier, monospace; | |
font-size: 90%; | |
overflow:auto; | |
} | |
table { border-collapse: collapse; } | |
td, th { vertical-align: top; } | |
dt { font-weight: bold; } | |
div.figure { padding: 0.5em; } | |
div.figure p { text-align: center; } | |
.linenr { font-size:smaller } | |
.code-highlighted {background-color:#ffff00;} | |
.org-info-js_info-navigation { border-style:none; } | |
#org-info-js_console-label { font-size:10px; font-weight:bold; | |
white-space:nowrap; } | |
.org-info-js_search-highlight {background-color:#ffff00; color:#000000; | |
font-weight:bold; } | |
/*]]>*/--> | |
</style> | |
<script type="text/javascript"> | |
<!--/*--><![CDATA[/*><!--*/ | |
function CodeHighlightOn(elem, id) | |
{ | |
var target = document.getElementById(id); | |
if(null != target) { | |
elem.cacheClassElem = elem.className; | |
elem.cacheClassTarget = target.className; | |
target.className = "code-highlighted"; | |
elem.className = "code-highlighted"; | |
} | |
} | |
function CodeHighlightOff(elem, id) | |
{ | |
var target = document.getElementById(id); | |
if(elem.cacheClassElem) | |
elem.className = elem.cacheClassElem; | |
if(elem.cacheClassTarget) | |
target.className = elem.cacheClassTarget; | |
} | |
/*]]>*///--> | |
</script> | |
</head> | |
<body> | |
<div id="content"> | |
<h1 class="title">Clojure</h1> | |
<div id="table-of-contents"> | |
<h2>Table of Contents</h2> | |
<div id="text-table-of-contents"> | |
<ul> | |
<li><a href="#sec-1">1 Use Clojure NOW </a> | |
<ul> | |
<li><a href="#sec-1.1">1.1 Documentation: a problem for new developers only </a></li> | |
<li><a href="#sec-1.2">1.2 Stacktraces/error messages: not as big a deal as you might think </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-2">2 Warning: </a> | |
<ul> | |
<li><a href="#sec-2.1">2.1 You'll probably hear me say "pragmattic" a lot </a></li> | |
<li><a href="#sec-2.2">2.2 I have drunk the cool-aid: I now use emacs.. enough said </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-3">3 What is clojure? A hosted Language </a> | |
<ul> | |
<li><a href="#sec-3.1">3.1 JVM </a></li> | |
<li><a href="#sec-3.2">3.2 Javascript </a></li> | |
<li><a href="#sec-3.3">3.3 CLR </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-4">4 What is clojure? A LISP </a> | |
<ul> | |
<li><a href="#sec-4.1">4.1 LISP-1 </a></li> | |
<li><a href="#sec-4.2">4.2 a little bit of Scheme, a little bit of Common LISP </a></li> | |
<li><a href="#sec-4.3">4.3 much more syntactic sugar than other LISPs </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-5">5 What is clojure? Function </a> | |
<ul> | |
<li><a href="#sec-5.1">5.1 Homoiconic </a></li> | |
<li><a href="#sec-5.2">5.2 Immutable by default </a></li> | |
<li><a href="#sec-5.3">5.3 Lazy </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-6">6 REPL </a> | |
<ul> | |
<li><a href="#sec-6.1">6.1 Read </a></li> | |
<li><a href="#sec-6.2">6.2 Eval </a></li> | |
<li><a href="#sec-6.3">6.3 Print </a></li> | |
<li><a href="#sec-6.4">6.4 Loop </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-7">7 What's it look like </a> | |
<ul> | |
<li><a href="#sec-7.1">7.1 everything is not a list () .. but close </a></li> | |
<li><a href="#sec-7.2">7.2 as with all LISPs: first Sexp is a function call in a list (func arg arg … ) </a></li> | |
<li><a href="#sec-7.3">7.3 (list 1 2 3) is just a list </a></li> | |
<li><a href="#sec-7.4">7.4 a (vector 1 2 3) is like an array (Perl, Ruby, Php) </a></li> | |
<li><a href="#sec-7.5">7.5 Now that you know those two … functions </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-8">8 OK, a few more data structures </a> | |
<ul> | |
<li><a href="#sec-8.1">8.1 Scalar literals: [ "string" true false nil \c \h \a \r ] </a></li> | |
<li><a href="#sec-8.2">8.2 :keywords are simply Keywords, that's all they are ( :namespace/keywords ) </a></li> | |
<li><a href="#sec-8.3">8.3 'symbol is a Symbol </a></li> | |
<li><a href="#sec-8.4">8.4 Numbers </a></li> | |
<li><a href="#sec-8.5">8.5 Regular Expressions </a></li> | |
<li><a href="#sec-8.6">8.6 (hash-map :a 1 :b 2) </a></li> | |
<li><a href="#sec-8.7">8.7 (hash-set :a :b :c :d) is a classical Set, in the mathematical/functional sense </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-9">9 Scope me out </a> | |
<ul> | |
<li><a href="#sec-9.1">9.1 Namespaces, are a way to scope Vars </a></li> | |
<li><a href="#sec-9.2">9.2 Let is way to add Vars to a local scope </a></li> | |
<li><a href="#sec-9.3">9.3 Clojure has closures … all functions when realized retain the value of their parent scope </a></li> | |
<li><a href="#sec-9.4">9.4 foo/x references x in namespace foo </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-10">10 Suck it up (list consumption) </a> | |
<ul> | |
<li><a href="#sec-10.1">10.1 (map (partial + 3) [1 2 3]) </a></li> | |
<li><a href="#sec-10.2">10.2 (filter #(even? %) (range 0 10)) </a></li> | |
<li><a href="#sec-10.3">10.3 (reduce + [1 2 3 4 5]) </a></li> | |
<li><a href="#sec-10.4">10.4 (apply str '[a b c]) </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-11">11 loopedy loo </a> | |
<ul> | |
<li><a href="#sec-11.1">11.1 (loop [x 5] </a></li> | |
<li><a href="#sec-11.2">11.2 (take 10 (for [x (range 10) y (range 10 20)] [x y])) </a></li> | |
<li><a href="#sec-11.3">11.3 (doseq [x (range 5)] </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-12">12 Interop(erator) </a> | |
<ul> | |
<li><a href="#sec-12.1">12.1 (.method from-object args) </a></li> | |
<li><a href="#sec-12.2">12.2 (instantiate. "with something new") </a></li> | |
<li><a href="#sec-12.3">12.3 static/FIELD<sub>ACCESS</sub> </a></li> | |
<li><a href="#sec-12.4">12.4 (.someField some-object) ;; instance field access </a></li> | |
<li><a href="#sec-12.5">12.5 you might like defrecord and friends </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-13">13 Pallet </a> | |
<ul> | |
<li><a href="#sec-13.1">13.1 project.clj </a></li> | |
<li><a href="#sec-13.2">13.2 Pallet! </a></li> | |
<li><a href="#sec-13.3">13.3 Interop Example (AMI) code </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-14">14 Everything together </a> | |
<ul> | |
<li><a href="#sec-14.1">14.1 Enlive / Enfocus </a></li> | |
<li><a href="#sec-14.2">14.2 Noir (compojure, ring) </a></li> | |
<li><a href="#sec-14.3">14.3 Clojurescript </a> | |
<ul> | |
<li><a href="#sec-14.3.1">14.3.1 What is it </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-14.4">14.4 wol-websockets </a></li> | |
</ul> | |
</li> | |
<li><a href="#sec-15">15 Storm </a></li> | |
<li><a href="#sec-16">16 Core.logic </a></li> | |
<li><a href="#sec-17">17 Cascalog </a></li> | |
<li><a href="#sec-18">18 The People </a></li> | |
<li><a href="#sec-19">19 Books </a></li> | |
<li><a href="#sec-20">20 Stuff you'll probably be interested in I haven't covered </a> | |
<ul> | |
<li><a href="#sec-20.1">20.1 STM </a></li> | |
<li><a href="#sec-20.2">20.2 Protocols (not OOP) </a></li> | |
<li><a href="#sec-20.3">20.3 Macros </a></li> | |
</ul> | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-1" class="outline-2"> | |
<h2 id="sec-1"><span class="section-number-2">1</span> Use Clojure NOW </h2> | |
<div class="outline-text-2" id="text-1"> | |
<p>Clojure is mature and production ready. | |
</p> | |
</div> | |
<div id="outline-container-1.1" class="outline-3"> | |
<h3 id="sec-1.1"><span class="section-number-3">1.1</span> Documentation: a problem for new developers only </h3> | |
<div class="outline-text-3" id="text-1.1"> | |
</div> | |
</div> | |
<div id="outline-container-1.2" class="outline-3"> | |
<h3 id="sec-1.2"><span class="section-number-3">1.2</span> Stacktraces/error messages: not as big a deal as you might think </h3> | |
<div class="outline-text-3" id="text-1.2"> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-2" class="outline-2"> | |
<h2 id="sec-2"><span class="section-number-2">2</span> Warning: </h2> | |
<div class="outline-text-2" id="text-2"> | |
</div> | |
<div id="outline-container-2.1" class="outline-3"> | |
<h3 id="sec-2.1"><span class="section-number-3">2.1</span> You'll probably hear me say "pragmattic" a lot </h3> | |
<div class="outline-text-3" id="text-2.1"> | |
</div> | |
</div> | |
<div id="outline-container-2.2" class="outline-3"> | |
<h3 id="sec-2.2"><span class="section-number-3">2.2</span> I have drunk the cool-aid: I now use emacs.. enough said </h3> | |
<div class="outline-text-3" id="text-2.2"> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-3" class="outline-2"> | |
<h2 id="sec-3"><span class="section-number-2">3</span> What is clojure? A hosted Language </h2> | |
<div class="outline-text-2" id="text-3"> | |
</div> | |
<div id="outline-container-3.1" class="outline-3"> | |
<h3 id="sec-3.1"><span class="section-number-3">3.1</span> JVM </h3> | |
<div class="outline-text-3" id="text-3.1"> | |
<ul> | |
<li> | |
most actively developed | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-3.2" class="outline-3"> | |
<h3 id="sec-3.2"><span class="section-number-3">3.2</span> Javascript </h3> | |
<div class="outline-text-3" id="text-3.2"> | |
<ul> | |
<li> | |
not a full port | |
</li> | |
<li> | |
"clojure in clojure" | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-3.3" class="outline-3"> | |
<h3 id="sec-3.3"><span class="section-number-3">3.3</span> CLR </h3> | |
<div class="outline-text-3" id="text-3.3"> | |
<ul> | |
<li> | |
a ground-up implementation that is designed to mirror the JVM implementation, but isn't as actively developed | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-4" class="outline-2"> | |
<h2 id="sec-4"><span class="section-number-2">4</span> What is clojure? A LISP </h2> | |
<div class="outline-text-2" id="text-4"> | |
</div> | |
<div id="outline-container-4.1" class="outline-3"> | |
<h3 id="sec-4.1"><span class="section-number-3">4.1</span> LISP-1 </h3> | |
<div class="outline-text-3" id="text-4.1"> | |
<p>functions share the same namespace as all other data structures (ala Scheme) | |
</p></div> | |
</div> | |
<div id="outline-container-4.2" class="outline-3"> | |
<h3 id="sec-4.2"><span class="section-number-3">4.2</span> a little bit of Scheme, a little bit of Common LISP </h3> | |
<div class="outline-text-3" id="text-4.2"> | |
<p>no, not CLOS | |
</p></div> | |
</div> | |
<div id="outline-container-4.3" class="outline-3"> | |
<h3 id="sec-4.3"><span class="section-number-3">4.3</span> much more syntactic sugar than other LISPs </h3> | |
<div class="outline-text-3" id="text-4.3"> | |
<p>[], {}, #{}, #"", #(), ', `, ~, @ | |
</p></div> | |
</div> | |
</div> | |
<div id="outline-container-5" class="outline-2"> | |
<h2 id="sec-5"><span class="section-number-2">5</span> What is clojure? Function </h2> | |
<div class="outline-text-2" id="text-5"> | |
</div> | |
<div id="outline-container-5.1" class="outline-3"> | |
<h3 id="sec-5.1"><span class="section-number-3">5.1</span> Homoiconic </h3> | |
<div class="outline-text-3" id="text-5.1"> | |
</div> | |
</div> | |
<div id="outline-container-5.2" class="outline-3"> | |
<h3 id="sec-5.2"><span class="section-number-3">5.2</span> Immutable by default </h3> | |
<div class="outline-text-3" id="text-5.2"> | |
<p>(def x 1) | |
</p></div> | |
</div> | |
<div id="outline-container-5.3" class="outline-3"> | |
<h3 id="sec-5.3"><span class="section-number-3">5.3</span> Lazy </h3> | |
<div class="outline-text-3" id="text-5.3"> | |
<p>we hang out in hammocks | |
</p></div> | |
</div> | |
</div> | |
<div id="outline-container-6" class="outline-2"> | |
<h2 id="sec-6"><span class="section-number-2">6</span> REPL </h2> | |
<div class="outline-text-2" id="text-6"> | |
</div> | |
<div id="outline-container-6.1" class="outline-3"> | |
<h3 id="sec-6.1"><span class="section-number-3">6.1</span> Read </h3> | |
<div class="outline-text-3" id="text-6.1"> | |
<p>(read-string "(+ 1 1)") | |
Clojurescript even has the reader in Javascript run-time | |
</p></div> | |
</div> | |
<div id="outline-container-6.2" class="outline-3"> | |
<h3 id="sec-6.2"><span class="section-number-3">6.2</span> Eval </h3> | |
<div class="outline-text-3" id="text-6.2"> | |
<p>(eval (read-string "(+ 1 1)")) | |
Clojurescript does not have eval | |
</p></div> | |
</div> | |
<div id="outline-container-6.3" class="outline-3"> | |
<h3 id="sec-6.3"><span class="section-number-3">6.3</span> Print </h3> | |
<div class="outline-text-3" id="text-6.3"> | |
<p>tell me bout it | |
</p></div> | |
</div> | |
<div id="outline-container-6.4" class="outline-3"> | |
<h3 id="sec-6.4"><span class="section-number-3">6.4</span> Loop </h3> | |
<div class="outline-text-3" id="text-6.4"> | |
<p>do it again | |
</p></div> | |
</div> | |
</div> | |
<div id="outline-container-7" class="outline-2"> | |
<h2 id="sec-7"><span class="section-number-2">7</span> What's it look like </h2> | |
<div class="outline-text-2" id="text-7"> | |
</div> | |
<div id="outline-container-7.1" class="outline-3"> | |
<h3 id="sec-7.1"><span class="section-number-3">7.1</span> everything is not a list () .. but close </h3> | |
<div class="outline-text-3" id="text-7.1"> | |
</div> | |
</div> | |
<div id="outline-container-7.2" class="outline-3"> | |
<h3 id="sec-7.2"><span class="section-number-3">7.2</span> as with all LISPs: first Sexp is a function call in a list (func arg arg … ) </h3> | |
<div class="outline-text-3" id="text-7.2"> | |
</div> | |
</div> | |
<div id="outline-container-7.3" class="outline-3"> | |
<h3 id="sec-7.3"><span class="section-number-3">7.3</span> (list 1 2 3) is just a list </h3> | |
<div class="outline-text-3" id="text-7.3"> | |
<ul> | |
<li> | |
singly linked-list | |
</li> | |
<li> | |
idiomatic '(1 2 3) | |
<ul> | |
<li> | |
(quote (1 2 3)) | |
</li> | |
</ul> | |
</li> | |
<li> | |
conj on front | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-7.4" class="outline-3"> | |
<h3 id="sec-7.4"><span class="section-number-3">7.4</span> a (vector 1 2 3) is like an array (Perl, Ruby, Php) </h3> | |
<div class="outline-text-3" id="text-7.4"> | |
<ul> | |
<li> | |
indexed | |
</li> | |
<li> | |
conj on tail | |
</li> | |
<li> | |
idiomatic: [1 2 3] | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-7.5" class="outline-3"> | |
<h3 id="sec-7.5"><span class="section-number-3">7.5</span> Now that you know those two … functions </h3> | |
<div class="outline-text-3" id="text-7.5"> | |
<ul> | |
<li> | |
(fn [x] (+ x x)) ;; lambda (anonymous) | |
</li> | |
<li> | |
(def square (fn [x] (+ x x)) ;; base form | |
</li> | |
<li> | |
(defn square [x] (+ x x)) ;; idiomatic form | |
</li> | |
<li> | |
#(+ % %) ;; idiomatic lambda | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-8" class="outline-2"> | |
<h2 id="sec-8"><span class="section-number-2">8</span> OK, a few more data structures </h2> | |
<div class="outline-text-2" id="text-8"> | |
</div> | |
<div id="outline-container-8.1" class="outline-3"> | |
<h3 id="sec-8.1"><span class="section-number-3">8.1</span> Scalar literals: [ "string" true false nil \c \h \a \r ] </h3> | |
<div class="outline-text-3" id="text-8.1"> | |
<ul> | |
<li> | |
strings | |
</li> | |
<li> | |
booleans | |
</li> | |
<li> | |
nil (not null) | |
</li> | |
<li> | |
characters: unicode, \space \newline etc | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-8.2" class="outline-3"> | |
<h3 id="sec-8.2"><span class="section-number-3">8.2</span> :keywords are simply Keywords, that's all they are ( :namespace/keywords ) </h3> | |
<div class="outline-text-3" id="text-8.2"> | |
</div> | |
</div> | |
<div id="outline-container-8.3" class="outline-3"> | |
<h3 id="sec-8.3"><span class="section-number-3">8.3</span> 'symbol is a Symbol </h3> | |
<div class="outline-text-3" id="text-8.3"> | |
<ul> | |
<li> | |
created with a quote | |
</li> | |
<li> | |
also used to denote Vars (def iama "symbol") | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-8.4" class="outline-3"> | |
<h3 id="sec-8.4"><span class="section-number-3">8.4</span> Numbers </h3> | |
<div class="outline-text-3" id="text-8.4"> | |
<ul> | |
<li> | |
division defaults to Rational | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-8.5" class="outline-3"> | |
<h3 id="sec-8.5"><span class="section-number-3">8.5</span> Regular Expressions </h3> | |
<div class="outline-text-3" id="text-8.5"> | |
<ul> | |
<li> | |
#"[jJ]a{1,5}m" | |
</li> | |
<li> | |
re-find, re-matches, etc | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-8.6" class="outline-3"> | |
<h3 id="sec-8.6"><span class="section-number-3">8.6</span> (hash-map :a 1 :b 2) </h3> | |
<div class="outline-text-3" id="text-8.6"> | |
<ul> | |
<li> | |
idiomatic: {:a 1 :b 2} | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-8.7" class="outline-3"> | |
<h3 id="sec-8.7"><span class="section-number-3">8.7</span> (hash-set :a :b :c :d) is a classical Set, in the mathematical/functional sense </h3> | |
<div class="outline-text-3" id="text-8.7"> | |
<ul> | |
<li> | |
idiomatic is #{:a :b :c :d} | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-9" class="outline-2"> | |
<h2 id="sec-9"><span class="section-number-2">9</span> Scope me out </h2> | |
<div class="outline-text-2" id="text-9"> | |
</div> | |
<div id="outline-container-9.1" class="outline-3"> | |
<h3 id="sec-9.1"><span class="section-number-3">9.1</span> Namespaces, are a way to scope Vars </h3> | |
<div class="outline-text-3" id="text-9.1"> | |
<ul> | |
<li> | |
(ns foo) … everything declared following and until the next namespace declarations, is in the foo names | |
</li> | |
</ul> | |
<p>pace | |
</p></div> | |
</div> | |
<div id="outline-container-9.2" class="outline-3"> | |
<h3 id="sec-9.2"><span class="section-number-3">9.2</span> Let is way to add Vars to a local scope </h3> | |
<div class="outline-text-3" id="text-9.2"> | |
<ul> | |
<li> | |
(let [x 1 y 2] (+ x y)) ; => 3 | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-9.3" class="outline-3"> | |
<h3 id="sec-9.3"><span class="section-number-3">9.3</span> Clojure has closures … all functions when realized retain the value of their parent scope </h3> | |
<div class="outline-text-3" id="text-9.3"> | |
<pre> | |
(let [square (fn [x] (* x x)) | |
cube (fn [y] (* y y y)) | |
joey (fn [x y] (+ (square x) (cube y)))] | |
(joey 2 3)) | |
</pre></div> | |
</div> | |
<div id="outline-container-9.4" class="outline-3"> | |
<h3 id="sec-9.4"><span class="section-number-3">9.4</span> foo/x references x in namespace foo </h3> | |
<div class="outline-text-3" id="text-9.4"> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-10" class="outline-2"> | |
<h2 id="sec-10"><span class="section-number-2">10</span> Suck it up (list consumption) </h2> | |
<div class="outline-text-2" id="text-10"> | |
</div> | |
<div id="outline-container-10.1" class="outline-3"> | |
<h3 id="sec-10.1"><span class="section-number-3">10.1</span> (map (partial + 3) [1 2 3]) </h3> | |
<div class="outline-text-3" id="text-10.1"> | |
<ul> | |
<li> | |
partial takes a 2 arg function and creates a new 1-arg function | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-10.2" class="outline-3"> | |
<h3 id="sec-10.2"><span class="section-number-3">10.2</span> (filter #(even? %) (range 0 10)) </h3> | |
<div class="outline-text-3" id="text-10.2"> | |
<ul> | |
<li> | |
of course (filter even? (range 0 10)) | |
</li> | |
<li> | |
functions? is convention for a fn that returns a Boolean value | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-10.3" class="outline-3"> | |
<h3 id="sec-10.3"><span class="section-number-3">10.3</span> (reduce + [1 2 3 4 5]) </h3> | |
<div class="outline-text-3" id="text-10.3"> | |
</div> | |
</div> | |
<div id="outline-container-10.4" class="outline-3"> | |
<h3 id="sec-10.4"><span class="section-number-3">10.4</span> (apply str '[a b c]) </h3> | |
<div class="outline-text-3" id="text-10.4"> | |
<ul> | |
<li> | |
(str '[a b c]) ;; => "[a b c]" | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-11" class="outline-2"> | |
<h2 id="sec-11"><span class="section-number-2">11</span> loopedy loo </h2> | |
<div class="outline-text-2" id="text-11"> | |
</div> | |
<div id="outline-container-11.1" class="outline-3"> | |
<h3 id="sec-11.1"><span class="section-number-3">11.1</span> (loop [x 5] </h3> | |
<div class="outline-text-3" id="text-11.1"> | |
<p>(if (neg? x) | |
x | |
(recur (dec x)))) | |
</p></div> | |
</div> | |
<div id="outline-container-11.2" class="outline-3"> | |
<h3 id="sec-11.2"><span class="section-number-3">11.2</span> (take 10 (for [x (range 10) y (range 10 20)] [x y])) </h3> | |
<div class="outline-text-3" id="text-11.2"> | |
<ul> | |
<li> | |
includes :let and :while bindings | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-11.3" class="outline-3"> | |
<h3 id="sec-11.3"><span class="section-number-3">11.3</span> (doseq [x (range 5)] </h3> | |
<div class="outline-text-3" id="text-11.3"> | |
<p>(println x)) | |
</p><ul> | |
<li> | |
only use for side effects | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-12" class="outline-2"> | |
<h2 id="sec-12"><span class="section-number-2">12</span> Interop(erator) </h2> | |
<div class="outline-text-2" id="text-12"> | |
</div> | |
<div id="outline-container-12.1" class="outline-3"> | |
<h3 id="sec-12.1"><span class="section-number-3">12.1</span> (.method from-object args) </h3> | |
<div class="outline-text-3" id="text-12.1"> | |
<ul> | |
<li> | |
(.substring "hello" 1 3) | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-12.2" class="outline-3"> | |
<h3 id="sec-12.2"><span class="section-number-3">12.2</span> (instantiate. "with something new") </h3> | |
<div class="outline-text-3" id="text-12.2"> | |
<ul> | |
<li> | |
(java.util.ArrayList. 100) | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-12.3" class="outline-3"> | |
<h3 id="sec-12.3"><span class="section-number-3">12.3</span> static/FIELD<sub>ACCESS</sub> </h3> | |
<div class="outline-text-3" id="text-12.3"> | |
</div> | |
</div> | |
<div id="outline-container-12.4" class="outline-3"> | |
<h3 id="sec-12.4"><span class="section-number-3">12.4</span> (.someField some-object) ;; instance field access </h3> | |
<div class="outline-text-3" id="text-12.4"> | |
</div> | |
</div> | |
<div id="outline-container-12.5" class="outline-3"> | |
<h3 id="sec-12.5"><span class="section-number-3">12.5</span> you might like defrecord and friends </h3> | |
<div class="outline-text-3" id="text-12.5"> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-13" class="outline-2"> | |
<h2 id="sec-13"><span class="section-number-2">13</span> Pallet </h2> | |
<div class="outline-text-2" id="text-13"> | |
</div> | |
<div id="outline-container-13.1" class="outline-3"> | |
<h3 id="sec-13.1"><span class="section-number-3">13.1</span> project.clj </h3> | |
<div class="outline-text-3" id="text-13.1"> | |
<pre> | |
(defproject co-working "0.1.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:url "<a href="http://example.com/FIXME"">http://example.com/FIXME"</a> | |
:license {:name "Eclipse Public License" | |
:url "<a href="http://www.eclipse.org/legal/epl-v10.html"}">http://www.eclipse.org/legal/epl-v10.html"}</a> | |
:dependencies [[org.clojure/clojure "1.3.0"] | |
[org.cloudhoist/pallet "0.7.0-SNAPSHOT"] | |
[org.cloudhoist/pallet-crates-all "0.5.0"] | |
[org.cloudhoist/java "0.7.0-SNAPSHOT"] | |
[org.cloudhoist/pallet-jclouds "1.3.0-beta.1"] | |
;; To get started we include all jclouds compute providers. | |
;; You may wish to replace this with the specific jclouds | |
;; providers you use, to reduce dependency sizes. | |
[org.jclouds/jclouds-allblobstore "1.3.2"] | |
[org.jclouds/jclouds-allcompute "1.3.2"] | |
[org.jclouds.driver/jclouds-slf4j "1.3.2"] | |
[org.slf4j/slf4j-api "1.6.1"] | |
[ch.qos.logback/logback-core "1.0.0"] | |
[ch.qos.logback/logback-classic "1.0.0"]] | |
:dev-dependencies [[lein-marginalia "0.7.0"] | |
[org.cloudhoist/pallet-lein "0.4.1"]] | |
:repositories {"sonatype" "<a href="https://oss.sonatype.org/content/repositories/releases"">https://oss.sonatype.org/content/repositories/releases"</a> | |
"sonatype-snapshots" "<a href="https://oss.sonatype.org/content/repositories/snapshots"}">https://oss.sonatype.org/content/repositories/snapshots"}</a>) | |
</pre></div> | |
</div> | |
<div id="outline-container-13.2" class="outline-3"> | |
<h3 id="sec-13.2"><span class="section-number-3">13.2</span> Pallet! </h3> | |
<div class="outline-text-3" id="text-13.2"> | |
<pre>(ns co-working.core | |
(:require | |
[pallet.core :as core] | |
[pallet.crate.automated-admin-user :as automated-admin-user] | |
[pallet.phase :as phase] | |
[pallet.session :as session] | |
[pallet.action.directory :as directory] | |
[pallet.action.user :as user] | |
[pallet.action.remote-file :as remote-file] | |
[pallet.resource.service :as service] | |
[pallet.crate.php :as php] | |
[pallet.crate.java :as java] | |
[pallet.crate.git :as git] | |
[pallet.crate.mysql :as mysql] | |
[pallet.resource.package :as package] | |
[pallet.action.exec-script :as exec-script] | |
[pallet.action.package :as package-action] | |
[pallet.configure :as configure] | |
[pallet.compute :as compute]) | |
(:use [pallet.thread-expr] | |
[clojure.pprint])) | |
</pre> | |
<pre> | |
(defn show-nodes | |
"A better node list" | |
[srvc] | |
(map #(vector (compute/id %) | |
(compute/primary-ip %) | |
(compute/group-name %)) | |
(compute/nodes srvc))) | |
</pre> | |
<pre> | |
(defn local-pallet-dir | |
"Get the .pallet dir of the user currently running pallet" | |
[] | |
(.getAbsolutePath | |
(doto (if-let [pallet-home (System/getenv "PALLET<sub>HOME</sub>")] | |
(java.io.File. pallet-home) | |
(java.io.File. (System/getProperty "user.home") ".pallet")) | |
.mkdirs))) | |
</pre> | |
<pre> | |
(defn- sane-package-manager | |
[request] | |
(-> request | |
(package/package-manager :universe) | |
(package/package-manager :multiverse) | |
(package/package-manager :update))) | |
(defn set-admin-user | |
"Use LSF conventions to assume locations of keys for admin-user" | |
[a-user] | |
(let [l-p-dir (local-pallet-dir)] | |
(core/admin-user a-user | |
:private-key-path (str l-p-dir "/" a-user "<sub>rsa</sub>") | |
:public-key-path (str l-p-dir "/" a-user "<sub>rsa</sub>.pub")))) | |
</pre> | |
<pre> | |
;(def ^:dynamic <b>admin-user</b> (set-admin-user "hadmin")) | |
(def ^:dynamic <b>admin-user</b> (set-admin-user "hadmin")) | |
</pre> | |
<pre> | |
(def co-worker-default-node | |
(core/node-spec | |
;:image {:image-id "us-east-1/ami-4dad7424"} ;; 64 bit 11.10 (Oneiric) EBS | |
:image {:os-family :ubuntu :os-version-matches "11.10"} | |
;:hardware {:min-ram 1024} | |
;:hardware {:hardware-id "m1.large"} | |
;:location {:location-id "us-east-1"} | |
:network {:inbound-ports [22 80]} ;; includes 9160, default cassandra client port | |
)) | |
</pre> | |
<pre> | |
(def with-base-server | |
(core/server-spec | |
:phases {:bootstrap (phase/phase-fn (automated-admin-user/automated-admin-user)) | |
:configure (phase/phase-fn (java/java :sun :bin :jdk)) | |
:java (phase/phase-fn | |
(java/java :openjdk :bin :jdk)) | |
:clojure (phase/phase-fn (clojure-development))})) | |
</pre> | |
<pre> | |
(def co-worker-cs | |
(core/group-spec | |
"co-worker-cs" | |
:extends [with-base-server] | |
:node-spec co-worker-default-node)) | |
</pre> | |
<pre> | |
(def rack-srvc (compute/compute-service-from-config-file :hrack)) | |
</pre> | |
</div> | |
</div> | |
<div id="outline-container-13.3" class="outline-3"> | |
<h3 id="sec-13.3"><span class="section-number-3">13.3</span> Interop Example (AMI) code </h3> | |
<div class="outline-text-3" id="text-13.3"> | |
<pre>(ns mms-cassandra-store.clone | |
(:import [org.jclouds.ec2.services AMIClient] | |
[org.jclouds.ec2.options CreateImageOptions] | |
[org.jclouds.compute.domain NodeMetadata]) | |
(:require | |
[pallet.core :as core])) | |
</pre> | |
<pre> | |
(defn- as-string | |
[v] | |
(cond | |
(string? v) v | |
(keyword? v) (name v) | |
:else v)) | |
</pre> | |
<pre> | |
(defn <sup>org</sup>.jclouds.ec2.services.AMIClient | |
ami-service | |
"" | |
[compute] | |
(-> compute | |
.getContext | |
.getProviderSpecificContext | |
.getApi | |
.getAMIServices)) | |
</pre> | |
<pre> | |
(defn create-image-in-region | |
([compute region name node-id description] | |
(.createImageInRegion | |
(ami-service compute) | |
;(get-region region) | |
region ;; this is problematic because of the region | |
(as-string name) | |
(as-string node-id) | |
(into-array CreateImageOptions | |
(when description | |
[(.withDescription (CreateImageOptions.) description)]))))) | |
</pre> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-14" class="outline-2"> | |
<h2 id="sec-14"><span class="section-number-2">14</span> Everything together </h2> | |
<div class="outline-text-2" id="text-14"> | |
</div> | |
<div id="outline-container-14.1" class="outline-3"> | |
<h3 id="sec-14.1"><span class="section-number-3">14.1</span> Enlive / Enfocus </h3> | |
<div class="outline-text-3" id="text-14.1"> | |
</div> | |
</div> | |
<div id="outline-container-14.2" class="outline-3"> | |
<h3 id="sec-14.2"><span class="section-number-3">14.2</span> Noir (compojure, ring) </h3> | |
<div class="outline-text-3" id="text-14.2"> | |
</div> | |
</div> | |
<div id="outline-container-14.3" class="outline-3"> | |
<h3 id="sec-14.3"><span class="section-number-3">14.3</span> Clojurescript </h3> | |
<div class="outline-text-3" id="text-14.3"> | |
</div> | |
<div id="outline-container-14.3.1" class="outline-4"> | |
<h4 id="sec-14.3.1"><span class="section-number-4">14.3.1</span> What is it </h4> | |
<div class="outline-text-4" id="text-14.3.1"> | |
<ul> | |
<li> | |
"clojure in clojure" | |
</li> | |
<li> | |
clojure-java compiler compiles down to javascript | |
</li> | |
<li> | |
google closure libraries and compiler | |
</li> | |
<li> | |
nodejs | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-14.4" class="outline-3"> | |
<h3 id="sec-14.4"><span class="section-number-3">14.4</span> wol-websockets </h3> | |
<div class="outline-text-3" id="text-14.4"> | |
</div> | |
</div> | |
</div> | |
<div id="outline-container-15" class="outline-2"> | |
<h2 id="sec-15"><span class="section-number-2">15</span> Storm </h2> | |
<div class="outline-text-2" id="text-15"> | |
<p>"Realtime Hadoop" | |
Deploy with Pallet | |
</p> | |
</div> | |
</div> | |
<div id="outline-container-16" class="outline-2"> | |
<h2 id="sec-16"><span class="section-number-2">16</span> Core.logic </h2> | |
<div class="outline-text-2" id="text-16"> | |
<ul> | |
<li> | |
PROLOG! | |
</li> | |
<li> | |
Core.Match | |
</li> | |
<li> | |
Freedman & Byrd and David Nolan | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-17" class="outline-2"> | |
<h2 id="sec-17"><span class="section-number-2">17</span> Cascalog </h2> | |
<div class="outline-text-2" id="text-17"> | |
</div> | |
</div> | |
<div id="outline-container-18" class="outline-2"> | |
<h2 id="sec-18"><span class="section-number-2">18</span> The People </h2> | |
<div class="outline-text-2" id="text-18"> | |
<p>Rich Hickey | |
'the stuarts' | |
Fogus | |
David Nolan | |
Chris Granger | |
</p> | |
</div> | |
</div> | |
<div id="outline-container-19" class="outline-2"> | |
<h2 id="sec-19"><span class="section-number-2">19</span> Books </h2> | |
<div class="outline-text-2" id="text-19"> | |
<p>Programming Clojure, Clojure Programming (Sierra), The Joy of Clojure | |
Clojure In Action | |
</p> | |
</div> | |
</div> | |
<div id="outline-container-20" class="outline-2"> | |
<h2 id="sec-20"><span class="section-number-2">20</span> Stuff you'll probably be interested in I haven't covered </h2> | |
<div class="outline-text-2" id="text-20"> | |
</div> | |
<div id="outline-container-20.1" class="outline-3"> | |
<h3 id="sec-20.1"><span class="section-number-3">20.1</span> STM </h3> | |
<div class="outline-text-3" id="text-20.1"> | |
<ul> | |
<li> | |
atoms, refs, agents | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div id="outline-container-20.2" class="outline-3"> | |
<h3 id="sec-20.2"><span class="section-number-3">20.2</span> Protocols (not OOP) </h3> | |
<div class="outline-text-3" id="text-20.2"> | |
</div> | |
</div> | |
<div id="outline-container-20.3" class="outline-3"> | |
<h3 id="sec-20.3"><span class="section-number-3">20.3</span> Macros </h3> | |
<div class="outline-text-3" id="text-20.3"> | |
</div> | |
</div> | |
</div> | |
<div id="postamble"> | |
<p class="author"> Author: | |
<a href="mailto:[email protected]"><[email protected]><br/> | |
<a href="http://about.me/huntar">about.me/huntar</a> | |
</p> | |
<p class="date"> Date: 2012-06-07 23:17:36 EDT</p> | |
<p class="creator">HTML generated by org-mode 6.33x in emacs 23</p> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment