Skip to content

Latest commit

 

History

History
108 lines (73 loc) · 2.16 KB

README.markdown

File metadata and controls

108 lines (73 loc) · 2.16 KB

ClojureScript 101

A living tutorial for ClojureScript.

Prerequisites

Build

To build the included source files, enter and run the following at a command prompt:

lein deps
lein cljsbuild once

Usage

To start ClojureScript 101 locally using Leiningen, type the following command in the project directory:

lein run 8080

Then visit http://localhost:8080/ and hack away.

Examples

Common ClojureScript functions and macros work as expected:

    (map (fn [n] (* n n n)) [1 2 3 4])
	;=> (1 8 27 64)
	
	(for [[k v] {:a 1 :b 2}] [v k])
	;=> ([1 :a] [2 :b])
	
	(if (< x 10) :less :more)
	;=> :less
	
	(defn sqr [n] (* n n))
	
	(map sqr [1 2 3])
	;=> (1 4 9)
	
	(deftype Cons [h t])
	
	(.-t (Cons. 1 108))
	;=> 108
	
	(defmulti classify-age :age)
	
	(defmethod classify-age 36 [_] :ancient)
	
	(classify-age {:age 36})
	;=> :ancient

JavaScript interop

To use jQuery from the ClojureScript 101 REPL, try the following:

    (def anchor (js/jQuery "a"))
	
	(.text anchor)
	;=> "Source..."
	
	(.text anchor "Github repo...")

Topics

  • ClojureScript 101
    • Target audience: those who know about ClojureScript but have never used it
    • Prerequisite: Clojure 101
    • Getting up and running
      • required tools: lein, editor, Java, etc.
      • lein cljs-build ...
    • Why ClojureScript?
    • Just enough ClojureScript
    • What is different from Clojure?
      • Compilation
      • Namespaces
      • Interop
      • Libraries
      • Briefly mention macros, more coverage in 102
    • Compilation
      • High level overview of compilation
      • Google Closure Compiler
      • Will be covered in more detail in ClojureScript 102
    • Namespaces
      • From a ClojureScript perspective
    • Basic JavaScript interop
      • The js magic namespace
      • Interact with JavaScript environment
    • Libraries
      • Using Google Closure libraries
      • Using jQuery

License

Copyright (C) 2014, Fogus

Distributed under the Eclipse Public License, the same as Clojure.