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

Short Tour Of Clojure

Short Tour Of Clojure

Tamizhvendan S

May 23, 2020
Tweet

More Decks by Tamizhvendan S

Other Decks in Programming

Transcript

  1. Lead Consultant www.ajira.tech Tamizhvendan S Passionate, Pragmatic and Polyglot Programmer

    https://www.demystifyfp.com tamizhvendan (short-tour (of (clojure)))
  2. Consistent Syntax 1. Adding the numbers one, two, three &

    four 2. Converting an integer to a string 3. Concatenating two strings 4. Conditional Operator
  3. Adding the numbers one, two, three & four 1 +

    2 + 3 + 4 Converting an integer to a string String.valueOf(1) Concatenating two strings "Hello, ".concat("World!")
  4. 1 + 2 + 3 + 4 function function function

    argument1 argument2 argument3 argument4 Infix Notation
  5. (String/valueOf 1) function argument1 class name static method argument(s) to

    the static method Clojure Syntax String.valueOf(1)
  6. (. "Hello, " concat "World!") function argument1 argument2 argument3 instance

    instance method argument(s) to the instance method special form Clojure Syntax "Hello, ".concat("World!")
  7. (if true "truthy" "falsy") function argument1 argument2 argument3 boolean value

    value1 value2 special form Clojure Syntax true ? "truthy" : "falsy"
  8. Types of Clojure Forms Atomic Data Type - Literals "Hello,

    World" 1 1.2 true nil \a :keyword symbol false
  9. Types of Clojure Forms Collection - Literals [1 "2" 3]

    '(1 1.2 1.5) {:one 1 :two 2 :three 3} #{1 2 3}
  10. Types of Clojure Forms Expressions (function invocation) (println "Hello, World!")

    (println "Hello," "World!") (+ 1 2 3 4) (String/valueOf 1) (. "Hello, " concat "World!")
  11. Expression always return a value user!=> (println "Hello, Clojure!") Hello,

    Clojure! nil  output of println function  return value of println function
  12. Clojure Evaluation Model (println "1 + 1 =" (+ 1

    1)) An expression begins with “(“
  13. Clojure Evaluation Model (println "1 + 1 =" (+ 1

    1)) function symbol println is a variadic function defined in the clojure.core namespace.
  14. Clojure Evaluation Model (println "1 + 1 =" (+ 1

    1)) argument1 string literal literals evaluate to itself
  15. Clojure Evaluation Model (println "1 + 1 =" (+ 1

    1)) An expression begins with “(“ argument2
  16. Clojure Evaluation Model (println "1 + 1 =" (+ 1

    1)) function symbol + is a variadic function defined in the clojure.core namespace.
  17. Clojure Evaluation Model (println "1 + 1 =" (+ 1

    1)) argument1 integer literal literals evaluate to itself
  18. Clojure Evaluation Model (println "1 + 1 =" (+ 1

    1)) argument2 integer literal literals evaluate to itself
  19. Clojure Evaluation Model (println "1 + 1 =" (+ 1

    1)) An expression ends with “)“
  20. Clojure Evaluation Model (println "1 + 1 =" 2) user!=>

    (println "1 + 1 =" (+ 1 1)) 1 + 1 = 2 nil  output of println function  return value of println function
  21. Clojure Evaluation Model Deviations Special Forms if . def let

    quote var fn loop recur Macros when condp -> ->> Macros are programs that write programs! try do
  22. Summary f(x) translates to (f x) f(x, y) translates to

    (f x y) o.m(x) translates to (. o m x) 1 + 2 + 3 + 4 translates to (+ 1 2 3 4) Prefix Notation