Clojure/West 2013 Conference Highlights Clojure/West 2013

Table of Contents

1. Overview

2. Schedule

2.1. Sunday: ClojureScript: Up and Running

http://clojurescript.eventbrite.com

  • Using the Leiningen build tool
  • Understanding the ClojureScript compiler
  • JavaScript interop and libraries
  • Working with the Google Closure Compiler
  • Using the Google Closure Libraries
  • Manipulating HTML in a browser
  • Building event-driven applications
  • Communicating with a Clojure server
  • collectiveworkspace

2.1.1. Slides

2.1.2. Discussion

  • Don't use the GClosure UI widgets since the OO style is a poor fit
  • Contrast with The Good Parts: human readability vs. optimization
  • cljx allows switching based on Clojure or Clojurescript environment

2.1.3. Compilations

  • Always run with warnings
{ :warnings :true } 
  • No sourcemap support at present but currently in progress
  • Development vs. production just change the meanings for :output-to and :output-dir
  • In production :output-to is full application and :output-dir is just an intermediate location
  • Always include :optimizations
  • Include clojurescript dependency for access in repl
src/cljs
resources/public/javascript
  • $ lein cljsbuild auto
  • Development HMTL: GClosure bootstrap, application, main namespace, function
  • Must be separate <script> calls
  • Production is just :output-to then call function

2.1.4. bREPL

  • Create the 3000 brepl.html test page
  • Create the 9000 endpoint
  • lein run
  • lein trampoline cljsbuild repl-listen
(js/alert 1)
(set! (.-title js/document) "New Page Title")

2.1.5. Differences and Interoperability

  • cljs.reader
  • https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure
  • Namespace: ns is built into the compiler and is only a subset of the Clojure ns
  • Concurrency primitives aren't available since JS is single-threaded: no refs, agents or futures
  • Doesn't change the Clojure single state: application state is stored in atoms, "State, Identity, and Value" http://clojure.org/state
  • Macros: :require-macros must be in the Clojure: define the macro in src/clj rather than src/cljs
  • Core algorithmic runtime characteristics for for data structures will be the same but there are constant changes that allow for improvements for the JavaScript run-time
  • js/ is the global JavaScript execution context
  • Examples won't work in IE for things like js/alert: alert() isn't a function in IE so a reference can't be found with call(window, alert)
  • When using JavaScript libraries that use "this" you need to call with (.my-method js/MyNamespace "my argument") otherwise use the idiomatic form of (MyNamespace/my-method "my argument")
  • A dot appended to the name of a function call it will be invoked with "new"

2.1.6. Labs

Flocking simulation.

https://github.com/jwalsh/boids

2.1.7. Namespaces and Dependencies

<body>
  <script src="build/deps.js"></script>
  <script>goog.require('boids.main');</script>
  <script type="text/javascript" src="file://localhost/Users/jwalsh/sandbox/boids/resources/public/build/goog/string/stringbuffer.js"></script>
  <script type="text/javascript" src="file://localhost/Users/jwalsh/sandbox/boids/resources/public/build/goog/../cljs/core.js"></script>
  <script type="text/javascript" src="file://localhost/Users/jwalsh/sandbox/boids/resources/public/build/goog/../boids/euclidean-vector.js"></script>
  <script>boids.main.main()</script>
  <canvas width="1383" height="831"></canvas>
</ body>

2.1.8. Manipulating Advanced

window.addEventListener(
  'mousemove', 
  function(e) {
    for (var p in boids.main.default_options.strobj) { 
      if(p.indexOf('goal') !== -1 && 
         p.indexOf('goal-') === -1) { 
        boids.main.default_options.strobj[p].tail = [e.x, e.y];  
      } 
    } 
    console.log(e.x)
  }, false)

2.1.9. Notes

  • Look at Clojurescript with Angular
  • Event SeattleJS noted difficultly with Ember
  • JS tooling system not well known (e.g., optimization options)

2.2. Sunday Evening: Ground Kontrol Pre-party

If you'll be in Portland Sunday night, stop by the legendary Ground Kontrol arcade (511 Northwest Couch Street, 97209), just a couple blocks from the conference hotel. We'll have the whole place reserved from 7-9 pm with FREE PLAY on all games and pinball machines! Two Sigma stepped up to sponsor the party so there will also be an open bar! Huge thanks to Two Sigma. Early registration will also be available.

2.3. Monday

2.3.1. Welcome, Alex Miller   theater

2.3.2. Cascalog: Logic programming over Hadoop, Alex Robbins   studio

  1. Slides
  2. Tasks
    1. TODO HTTP Archive with Cascalog taps
      • Create tap for ingesting
      • HDFS with TSV

2.3.3. RESTful Clojure, Siva Jagadeesan   studio

  1. Goals

    Look at order cancellation process that would be:

    • Scalablable
    • Maintainable
    • Recoverable
    • Loosely coupled
    • Secure

    Allow for version and status that could be provided by a client.

    • Spread complexity
    • Reduce complexity
    • Make complexity learnable
    • Definition driven with emphasis on Fielding rather than practice
    • Look at Richardson's macurity model.
    • Seems to care about "what is RESTful"
  2. v1 (actions parameter)
    • Set up the Compjure routes
    • Single end-ping
    • No caching
    • Has side-effects

    Use parameters as

  3. v2 (URI)

    General Rails approach.

    /GET

  4. v3 (uniform interface)

    General overview of HTTP status codes.

    /POST /GET /GET/1 /DELETE

    Application state transition logic is encoded in the clinet

  5. v4 (hypermedia/hypertext awareness)

    Now includes the links as part of the payload (resource states).

    Questionable if this is valuable in practice during initial product definition unless the end-points are only internal…do the names mean the same things over time (even with versioning).

    The question is how much cost there is for client libraries but the hypermedia links are more stable but one migrates the cost from the change in the server end-point (i.e., the URI) rather than the name of the media links.

    Is the caching definition a valid contract with the client?

  6. Version
    • URI
    • Media type considered better
  7. Tasks

    Attempts to have a level/design based analysis of end-points.

    Look at Netflix API which was considered the only RESTful API.

2.3.4. Engines of Abstraction, Jim Duey   theater

  1. Topics
    • monads
    • composition
    • applicative functors
    • comonads

    https://pinboard.in/u:jwalsh/t:cljweoa

2.3.5. Clojure in the Large, Stuart Sierra   theater

  1. Design
    @INPROCEEDINGS{Foote97bigball,
        author = {Brian Foote and Joseph Yoder},
        title = {Big Ball of Mud},
        booktitle = {Pattern Languages of Program Design},
        year = {1997},
        pages = {653--692},
        publisher = {Addison-Wesley}
    }
    
  2. Globals, State, Constructors
    ;; Problem
    (def state-1 (ref {}))
    
    ;; Hiding
    (let [state-1 (ref {})])
    
    ;; Use constructors
    (defn constructor []
      {: (ref {})})
    
    
    
  3. System
    (defrecord System)
    

2.3.6. Pedestal: Architecture and Services, Brenton Ashworth, Tim Ewald   theater clojurescript

  1. Ring restructuring

    Clojure, ClojureScript and EDN

  2. Server-sent events (SSE)
  3. Apps and Views

    Messages include topic and type, param.

2.3.7. Pedestal: Rich Client Applications, Brenton Ashworth, Tim Ewald   theater

  1. Running
    lein new pedestal-service my-service
    lein new pedestal-app my-app
    

2.3.8. Beyond Contracts: An exploration into unified specifications, Paul deGrandis   theater

2.3.9. Design, Composition, and Performance, Rich Hickey   theater

2.3.10. Monads, Unsession   seq1

Began by looking at the type of atoms that can be wrapped in Clojure.

  1. Sequences
    • define bind (flatten)
    ;; Sequence monadic function
    (defn bind [mv mf] (apply concat (map mf mv))) 
    
    • sequence monads
    • result map and flatten

    For other cases what we see are

    (defn f [x] (hash-set (* 5 x) (* 2 x)))
    (defn g [x] (hash-set (+ 5 x) (+ 2 x)))
    (f 3)
    (g 3)
    (defn bind [mv mf] (apply clojure.set/union (map mf mv))) 
    

    This bind and hash-set obey the monadic laws.

  2. Functions

    This requires flattening of a function: takes a value and returns a fn.

    (*1) ;; executes 
    (defn bind [mv mf] (let [x (mv) new-mv (mf x)] (fn [] (new-mv))))
    (defn f [x] (constantly (* 5 x)))
    (bind (constantly 5) f)
    (*1)
    

    Without mf taking a parameter this is largely useless.

  3. State Monad

    Allows global mutable state with pure functions.

    (defn result [x] (fn [state] [x state]))
    (result 1)
    (*1 :ok)
    
    

    Gives you a way (e.g., in Haskell) the flow through the application giving global mutable state.

2.3.11. Profiling Clojure, Unsession   seq1

  • VisualVM
(defn baz [n] (-> n (.replaceAll "2" "3") (.replaceAll "4" "5") ))

2.3.12. Functional Reactive Programming, Unsession   seq1

2.3.13. TODO Key Signing, Unsession   seq1

2.4. Tuesday

2.4.1. Winning the War on Javascript, Bodil Stokke   theater clourescript

  • Need klass system in Clojurescript
  • Promises as implemented in Clojurescript
  • Red Lobster and Dog Fort
  • Promises: p/realize p/on-realised; chained promises
(p/realise p p*) 

2.4.2. Metaprogramming Polyfill: Feed Clojure Data to your JavaScript Libraries, Tom White   theater

2.4.3. Securing Clojure webapps and services with Friend, Chas Emerick   theater

  • Authentication
  • Authorization

2.4.4. clj-v8 and the Dieter Asset Pipeline, Paul Biggar   studio

This was discussed as part of Clojure/West 2012.

2.4.5. FRP in ClojureScript with Flapjax, Alan Dipert   theater clojurescript

See associated links for FRP: https://pinboard.in/u:jwalsh/t:frp

2.4.6. Introducing ClojureScript-in-ClojureScript, Joel Martin   theater clojurescript

  • cljs debugger on page
  • text/clojurescript
  • namespaced cljs interop
  • externally referenced script src

2.5. Tuesday Evening: miniKanren Confo

2.5.1. Logic programming in the wild, Gabriel Pickard

2.5.2. Intro to CLP with core.logic, Ryan Senior

2.5.3. Molog: Typed Functional Logic Programming in Haskell, Adam Foltzer

2.5.4. The Architecture of core.logic, David Nolen

2.5.5. core.logic.nominal, Nada Amin

2.5.6. The Unreasonable Schemers, Dan Friedman and William Byrd

2.6. Wednesday

2.6.1. Editing Clojure Effectively with Emacs, Ryan Neufeld   studio emacs

  1. REPL and paredit
  2. Starter Kit + additional options
  3. Additions
  4. NREPL
    • M-.
  5. paredit
  6. Reinstall peepopen

2.6.2. Ritz - the missing Clojure tooling, Hugo Duncan   studio emacs

  1. nrepl-ritz-jack-in
  2. exception filters

    Enable via the configuration:

    (setq nrepl-popup-stacktraces-in-repl t)
    
    • adding filter from the stack trace
    • edit
    • disable
    • expand a specific frame
    • view source for a frame with "v"
  3. nrepl-ritz-threads

2.6.3. A shorter path from Clojure to Clojurescript, Roman Gonzalez   studio

Translating Clojure to Clojurescript

  • -invoke vs. invoke
  • :require vs. :require-macro
  1. DALAP

    https://github.com/BirdseyeSoftware/lein-dalap

    • cljx
    • valid clojure as input and clojurescript as out
    • selectors and transformers of the clojure data structures (ala CSS)

    Create a dalaprules.clj file with the selectors:

    • don't include some forms in the Clojurescript out

    There are some default rule s for

    • java.lang.String and String
    • defref and -deref

    But this doesn't cover any differences in the semantics between Java and JavaScript.

  2. Testing

    Clojurescript testing was the normal list:

    • jasmine
    • qunit
    • buster-cljs

    Wrapper of clojure.test:

    https://github.com/BirdseyeSoftware/buster-cljs

2.6.4. Lightning talks

2.6.5. Simulation Testing with Simulant, Stuart Halloway   theater

2.6.6. Racket: Metaprogramming Time!, Matthew Flatt   theater

Author: Jason Walsh Jason Walsh

Created: 2024-08-12 Mon 20:45

Validate