Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Munich Clojure Workshop - 01 - Introduction

Munich Clojure Workshop - 01 - Introduction

Copyright © 2012-2014 Clojure Workshop Team: Maximilian Karasz, Jan Stępień, Marek Kubica, Oleksandr Petrov

Commercial use of complete work or parts of work is not allowed to anyone except for Clojure Workshop Team at whole or in parts.

Licensed under Creative Commons Attribution-NonCommercial 3.0: http://creativecommons.org/licenses/by-nc/3.0/

When using complete work or parts of work, explicit attribution is required.

Clojure Workshops

October 11, 2013
Tweet

More Decks by Clojure Workshops

Other Decks in Technology

Transcript

  1. • Extremely expressive • First-class functions • Awesome Java Interoperability

    • Power of lisp (macros, function composition) • FUNctional Friday, October 11, 13
  2. • sane development environment, integrated with a language • ability

    to develop and evaluate things on the fly • ease maintenance production • scalability • integration with well-known / existing tools • good, stable runtime • runtime debugging toolkit • performance Friday, October 11, 13
  3. • Leiningen, Clojure build tool https://github.com/technomancy/leiningen • repl just run

    `lein repl` in your console • emacs (it’s written in lisp, you know?) excellent nrepl and (older thing) clojure-swank, paredit-mode, formatting • nrepl get to the guts of runtime • VisualVm and the rest of Java goodness like jmap, jstack, jstat etc etc etc Friday, October 11, 13
  4. • JMX java management extensions • nrepl • JVM configuration/tuning

    • No shared mutable state • No locks • Pure functions -> same input -> same output • Easy composition and pipelining Friday, October 11, 13
  5. • Good baseline performance • Utilization of all processor resources

    anyone can eat out all the memory, right? • Painless parallel execution • Memory efficiency as far as it is possible with lisps, of course. in my mind that was mostly about structural sharing & persistent DS • JIT / inlining Friday, October 11, 13
  6. • Very, very good Java interop options • Most of

    libraries are either ported to Clojure, or use Java library underneath • Your favorite Java application container / web server • Jar packaging / public / private Maven repositories • Not to replace, but to complement your existing JVM toolkit Friday, October 11, 13
  7. (defn square "Returns a square of a number" [x] (*

    x x)) Function Definition Argument (s) Function Body Docstring Friday, October 11, 13
  8. (map (fn [i] (+ i 1)) [1 2 3]) Function

    call Passed (anonymous) function Friday, October 11, 13
  9. function (a, b, c) { var sum = a +

    b + c; var count = 3; return sum / count; } Friday, October 11, 13
  10. (fn [a b c] (let [sum (+ a b c)

    count 3] (/ sum count)) Friday, October 11, 13
  11. • Sometimes referred as “control structures” • Expressions, often implemented

    as macros • Used to delay evaluation of certain code blocks Friday, October 11, 13
  12. Imagine “if” were a function for a minute: (if-fn (even?

    2) (println "even!") (println "odd!")) Both “even!” and “odd!” are printed. Friday, October 11, 13
  13. • Useful when you don’t have “false” part • You

    can write more than one expression within `where` block Friday, October 11, 13
  14. (def user {:name "Alex"}) (if-let [name (:name user)] (println "Hello

    " name) (println "Name is empty")) Friday, October 11, 13
  15. • Useful when you need to check an expression and

    reuse the expression result in “truth” block • As the name itself states, if-let behaves as let wrapped over if Friday, October 11, 13
  16. (cond (< n 0) "negative" (> n 0) "positive" :else

    "zero") Friday, October 11, 13
  17. • Useful when you want to avoid multiple nested ifs

    • `:else` here is arbitrary, you can use any expression that evaluates to something truthful Friday, October 11, 13
  18. • arrange into groups of 2-3 people • you’ll be

    given a function name and parameters vector • tests are located under `test/workshop_tasks/*-test.clj • write a function, run the tests • submit results to exercise server Friday, October 11, 13