SlideShare una empresa de Scribd logo
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Clojure through the
eyes of a Java Nut
Kannan Ramamoorthy
Principal Engineer
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● (Used to be) A strong believer that “OOPS is a natural way to design real-
world problems.”
● (Used to) Read & chat a lot about Java and Spring with fellow Java
developers.
● Still a Java developer.
● Not a ‘Know-it-all’ Clojure guy. Hence, one among the Java user tribe.
About Me:
2 2
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Not a Clojure vs Java comparison.
● Not a Clojure Tutorial.
● Probably won’t be able to use/try Clojure right away.
● My personal experience on how it ‘feels’ to use Clojure.
● Throw light on Clojure world.
3 3
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer
● Amusing Parts
● Hard parts
● Gotchas
● Questions
4 4
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer - [About,..]
● Amusing Parts
● Hard parts
● Gotchas
● Questions
5 5
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● A dynamically typed
● Functional programming language
● Lisp family
● Runs on JVM
● 100% Java
Clojure Primer - About:
6 6
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer - [About, Syntax...]
● Amusing Parts
● Hard parts
● Gotchas
● Questions
7 7
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
(operator <operand1> <operand2> ..)
Clojure Primer - (Over)simplified Syntax:
8 8
Special construct/Function/Macro
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Special construct:
Built in language constructs.
Function:
Functions that can be defined by us. Equivalent to Java’s methods.
Macro:
#Later
Clojure Primer - Definitions:
9 9
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer - [About, Syntax, Evaluation Model]
● Amusing Parts
● Hard parts
● Gotchas
● Questions
10 10
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Clojure Primer - (Over)simplified Evaluation model:
11 11
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer
● Amusing Parts
● Hard parts
● Gotchas
● Questions
12 12
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer
● Amusing Parts
● Hard parts
● Gotchas
● Questions
13 13
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● As mentioned in primer, (operator <argument1> <argument2> ..)
Examples,
Simple Syntax:
14 14
Expression Meaning
(+ 1 2) 'Add' 1 and 2.
(= v1 v2) 'Equality check' for values of 'v1'
and 'v2'.
(ns new-name-space) 'Switches namespace' to “new-
name-space”. (Namespace is
equivalent to Java’s package)
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Expression Meaning
(println “Test String”) 'Prints' the given string.
(def v 1) 'Define' a variable ‘v’ with value 1
(in the current namespace)
(defn prn [x] (prinln x)) 'Define' a function named 'prn' that
accepts a parameter and prints it.
Simple Syntax (cont..):
15 15
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Less Special Constructs:
16 16
● Special constructs are the basic building blocks of a language.
● Provided the special constructs, you will be able to build the whole
language yourself.
● If you wish, you could define the whole language by yourself.
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Less Special Constructs (cont..):
17 17
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
We can definition of short-circuit or (||) as below,.
(defmacro ||
"Equivalent of or"
([] nil)
([expr]
`~expr)
([expr & other-exprs]
`(let [val# (|| ~expr)]
(if val# val# (|| ~@other-exprs)))))
Less Special Constructs (cont..):
18 18
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Infinite/lazy sequence
19 19
(print (take 2 (list 0 1 2 3 4)))
; (0 1)
(print (take 2 (range)))
; (0 1)
(print (take 10 (range)))
; (0 1 2 3 4 5 6 7 8 9)
(print (take 1000000 (range)))
; Prints first 1M numbers
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Lazy sequences are common in Clojure.
● (Most of the cases) normal sequence can be replaced with lazy
sequence, helps in deferring the computation until its needed.
Infinite/lazy sequence (cont...)
20 20
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Introducing 2 new construct before going into detail.
List
(list 1 2 “three”)
; This creates a list with elements 1, 2 and “three”
In short-form the above notation can be written as,
‘(1 2 “three”)
Program as Data:
21 21
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Quote
(quote (+ 1 2))
; Returns the expression as is, i.e., (+ 1 2)
In short form this can be written as,
‘(+ 1 2)
Program as Data (cont...):
22 22
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Does that ring a bell?
● After seeing the below Clojure snippets?
(print “string”)
(take 2 (list 1 2 3))
● Isn’t the above code looks like a list without quote?
● All the Clojure programs are just nested list (Homoiconicity).
Program as Data (cont...):
23 23
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Lets you create DSL or custom syntactic abstraction without having to
be wait for language support.
● Things like ‘Enhanced switch’ in Java 13 doesn’t excite you much. You
can write it yourself if you want.
● For ex, you can define a macro that can be used like this which ends
up adding the numbers that you specify.
(evaluate add "1,2,3 and 4")
Macros (revisited):
24 24
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Lets you do CSP (Communicating Sequential Process) style
programming.
● Defines threads as go -blocks and channels for inter-
communication.
● Comparable to ‘Thread’ communicating with blocking queues in Java.
● Special highlight feature (alts!!), which lets you wait on multiple
channels.
(alts!! [channel1 channel2 channel3])
core.async (CSP) :
25 25
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● CLP - let’s you define the constraint of your problem and one or
generic algorithms solve the problem for you.
● At a high-level, you say “what is your problem?” the framework will
figure out “how to solve it?”
● Classical applications, “n-queens”, “sudoku”, “Timetable creation”, etc.
core.logic (CLP):
26 26
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
core.logic (CLP) - example:
27 27
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Lets you write a sophisticated switch-case style matching.
Example,
(match [x y z]
[_ 1 2] 1
[1 2 _ ] 2
[_ _ 1] 3
[_ _ 2] 4
:else 5)
core.match:
28 28
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Has a Isomorphic counterpart ClojureScript (CLJS)
● Write Clojure that can be compiled to Javascript.
● Lets you code make use of all the goodness of Clojure for browser.
Isomorphic:
29 29
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Less verbose, short and sweet code.
● Powered by syntactic abstractions and abstract, reusable functions
definitions.
● Some examples….
Conciseness:
30 30
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Cartesian product:
(for [x '(1 2 3) y '(1 2 3)] [x y])
;; Return ([1 1] [1 2] [1 3] [2 1] [2 2]
[2 3] [3 1] [3 2] [3 3])
Conciseness example:
31 31
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Reading a file:
(slurp "/Users/me/sample.txt")
(slurp "https://google.com")
(slurp "ftp://localhost:2121/sample.txt")
Conciseness example:
32 32
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Fibonacci solution that you can tweet:
(def fib
(lazy-cat [0 1] (map + (rest fib) fib)))
(take 10 fib)
; Prints (0 1 1 2 3 5 8 13 21 34)
Conciseness example:
33 33
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Wrap your function so that the result of the function is cached for a
given parameter and returned on consecutive call.
● Reusable a caching implementation that can wrap any applicable
functions.
● ‘Referential Transparency’ of most of the functions makes it easy to
memoize it.
Memoization:
34 34
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● With all the goodness of Clojure, you can also have access to the
ocean of Java library.
(println (System/currentTimeMillis))
; prints Current time in milliseconds.
(doto (new java.util.HashMap)
(.put "one" 1)
(.put "two" 2))
; Calls put(“one”, 1) and put(“two”,2)
; a new hashmap.
Java Interop:
35 35
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer
● Amusing Parts
● Hard parts
● Gotchas
● Questions
36 36
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer
● Amusing Parts
● Hard parts
● Gotchas
● Questions
37 37
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Parentheses is not arbitrary as in Java, ex, (+ 1 2 3) cannot be
written as (+ 1 (2 3))
● Naturally, takes some time to adopt for Java developers.
Usage of parentheses:
38 38
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Understand that each parentheses is a unquoted list and the first
element is expected to be an operand.
● Use an IDE to have the code properly formatted.
Overcoming - Usage of parentheses:
39 39
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Shift to s-expression:
● Mental shift to expressions of style (operator operand1
operand2)especially for the operators where order matters.
Example,
(> 2 1) ; Checks if 2 is greater than 1
(< 1 2) ; Checks if 1 is less than 2
40 40
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Unlearn the conventional meaning and read the docs for the
operators. Meanings for operators in Clojure may slightly differ.
Ex,
> means if the following numbers are in descending order
< means if the following numbers are in ascending order
● Practice
Overcoming s-expression shift:
41 41
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● All the Clojure’s core data structures are immutable.
● One of the MOST DIFFICULT part for a Java developer.
Immutable Data Structures:
42 42
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Don’t go with the easy ways of working around with immutable types.
● We naturally think using loops. Rather practice using map, reduce and
recursion.
Overcoming difficulty with Immutable Data Structures:
43 43
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● It takes time to get the significance of Macro.
● Having not used to meta-programming, choice of when to use macro
will be challenging.
● Understanding the scope of variables used in execution for a Macro
will be difficult.
Programming with Macro:
44 44
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Try implementing the out-of-box macros as functions and see if it is
possible.
● Using Macro for syntactic abstraction is a good choice. For everything
else
● WRT the scope, getting mental model of 2-level of execution helps.
● Practice.
Overcoming Macro usage difficulty:
45 45
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
● Lazy sequence itself is hard to imagine initially.
● Implementing one by yourself also bit hard initially.
Overcoming:
Understand, the power of lazy sequence is the implementation of the
consumer. Try understand how it works and try solving it.
Lazy sequence:
46 46
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer
● Amusing Parts
● Hard parts
● Gotchas
● Questions
47 47
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer
● Amusing Parts
● Hard parts
● Gotchas
● Questions
48 48
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Question: You say core data structures are not mutable. So how a
very basic use case of addition or deletion of the element from a
data structure is addressed?
Gotchas:
49 49
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Answer:
Clojure does support those operations. But it doesn’t change the
original data structure.
For ex,
(def a [1 2]) ; Define a vector with 1,2
(println (conj a 3)) ; Append 3 to it
;; Prints [1 2 3]
(println a)
;; Prints [1 2]
Gotchas:
50 50
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Question: What?! Do you create a new collection for each change
that we do? Aren’t you filling up the memory unnecessarily?
Gotchas:
51 51
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Answer:
Nope. Clojure uses a mechanism called Persistent Data structure,
which doesn’t actually create a new object but reuses the existing one
and still having the variables immutable.
Gotchas:
52 52
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Question: It is nice that the programs are concise. But anyhow,
under the hood it boils down to so many lines of Java code? What
is so nice about conciseness?
Gotchas:
53 53
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
Answer:
● Programming with less code could probably means more
productivity.
● But surely means less testing, if you are building on top of existing
and pre-tested code. In that way, conciseness matters.
Gotchas:
54 54
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer
● Amusing Parts
● Hard parts
● Gotchas
● Questions
55 55
Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved.
This Talk?
● Clojure Primer
● Amusing Parts
● Hard parts
● Gotchas
● Questions
56 56

Más contenido relacionado

La actualidad más candente

Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...Kuntal Bhowmick
 
The Ring programming language version 1.7 book - Part 89 of 196
The Ring programming language version 1.7 book - Part 89 of 196The Ring programming language version 1.7 book - Part 89 of 196
The Ring programming language version 1.7 book - Part 89 of 196Mahmoud Samir Fayed
 
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...Kuntal Bhowmick
 
Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...
Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...
Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...Kuntal Bhowmick
 
L Fu - Dao: a novel programming language for bioinformatics
L Fu - Dao: a novel programming language for bioinformaticsL Fu - Dao: a novel programming language for bioinformatics
L Fu - Dao: a novel programming language for bioinformaticsJan Aerts
 
Learn2Sign : Sign language recognition and translation using human keypoint e...
Learn2Sign : Sign language recognition and translation using human keypoint e...Learn2Sign : Sign language recognition and translation using human keypoint e...
Learn2Sign : Sign language recognition and translation using human keypoint e...Universitat Politècnica de Catalunya
 

La actualidad más candente (6)

Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
 
The Ring programming language version 1.7 book - Part 89 of 196
The Ring programming language version 1.7 book - Part 89 of 196The Ring programming language version 1.7 book - Part 89 of 196
The Ring programming language version 1.7 book - Part 89 of 196
 
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
 
Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...
Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...
Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...
 
L Fu - Dao: a novel programming language for bioinformatics
L Fu - Dao: a novel programming language for bioinformaticsL Fu - Dao: a novel programming language for bioinformatics
L Fu - Dao: a novel programming language for bioinformatics
 
Learn2Sign : Sign language recognition and translation using human keypoint e...
Learn2Sign : Sign language recognition and translation using human keypoint e...Learn2Sign : Sign language recognition and translation using human keypoint e...
Learn2Sign : Sign language recognition and translation using human keypoint e...
 

Similar a Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies

Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018Rafał Leszko
 
From shipping rpms to helm charts - Lessons learned and best practices
From shipping rpms to helm charts - Lessons learned and best practicesFrom shipping rpms to helm charts - Lessons learned and best practices
From shipping rpms to helm charts - Lessons learned and best practicesAnkush Chadha, MBA, MS
 
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018Taro L. Saito
 
Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowKathy Brown
 
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17Taro L. Saito
 
Developing Your Own Flux Packages by David McKay | Head of Developer Relation...
Developing Your Own Flux Packages by David McKay | Head of Developer Relation...Developing Your Own Flux Packages by David McKay | Head of Developer Relation...
Developing Your Own Flux Packages by David McKay | Head of Developer Relation...InfluxData
 
Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018
Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018
Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018Semihalf
 
Lesson slides for C programming course
Lesson slides for C programming courseLesson slides for C programming course
Lesson slides for C programming courseJean-Louis Gosselin
 
MySQL 8.0: What Is New in Optimizer and Executor?
MySQL 8.0: What Is New in Optimizer and Executor?MySQL 8.0: What Is New in Optimizer and Executor?
MySQL 8.0: What Is New in Optimizer and Executor?Norvald Ryeng
 
Clojure: Programming self-optimizing webapps in Lisp
Clojure: Programming self-optimizing webapps in LispClojure: Programming self-optimizing webapps in Lisp
Clojure: Programming self-optimizing webapps in LispStefan Richter
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of PrestoTaro L. Saito
 
Scaling Prometheus Metrics in Kubernetes with Telegraf | Chris Goller | Influ...
Scaling Prometheus Metrics in Kubernetes with Telegraf | Chris Goller | Influ...Scaling Prometheus Metrics in Kubernetes with Telegraf | Chris Goller | Influ...
Scaling Prometheus Metrics in Kubernetes with Telegraf | Chris Goller | Influ...InfluxData
 
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)Igalia
 
Meetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaCMeetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaCDamienCarpy
 
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17Muga Nishizawa
 
Break up the Monolith: Testing Microservices
Break up the Monolith: Testing MicroservicesBreak up the Monolith: Testing Microservices
Break up the Monolith: Testing MicroservicesMarcus Merrell
 
Перехват функций (хуки) под Windows в приложениях с помощью C/C++
Перехват функций (хуки) под Windows в приложениях с помощью C/C++Перехват функций (хуки) под Windows в приложениях с помощью C/C++
Перехват функций (хуки) под Windows в приложениях с помощью C/C++corehard_by
 
Big Decimal: Avoid Rounding Errors on Decimals in JavaScript
Big Decimal: Avoid Rounding Errors on Decimals in JavaScriptBig Decimal: Avoid Rounding Errors on Decimals in JavaScript
Big Decimal: Avoid Rounding Errors on Decimals in JavaScriptIgalia
 
Functional programming, TypeScript and RXJS
Functional programming, TypeScript and RXJSFunctional programming, TypeScript and RXJS
Functional programming, TypeScript and RXJSVivek Tikar
 
On component interface
On component interfaceOn component interface
On component interfaceLaurence Chen
 

Similar a Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies (20)

Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
 
From shipping rpms to helm charts - Lessons learned and best practices
From shipping rpms to helm charts - Lessons learned and best practicesFrom shipping rpms to helm charts - Lessons learned and best practices
From shipping rpms to helm charts - Lessons learned and best practices
 
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
 
Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To Know
 
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
 
Developing Your Own Flux Packages by David McKay | Head of Developer Relation...
Developing Your Own Flux Packages by David McKay | Head of Developer Relation...Developing Your Own Flux Packages by David McKay | Head of Developer Relation...
Developing Your Own Flux Packages by David McKay | Head of Developer Relation...
 
Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018
Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018
Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018
 
Lesson slides for C programming course
Lesson slides for C programming courseLesson slides for C programming course
Lesson slides for C programming course
 
MySQL 8.0: What Is New in Optimizer and Executor?
MySQL 8.0: What Is New in Optimizer and Executor?MySQL 8.0: What Is New in Optimizer and Executor?
MySQL 8.0: What Is New in Optimizer and Executor?
 
Clojure: Programming self-optimizing webapps in Lisp
Clojure: Programming self-optimizing webapps in LispClojure: Programming self-optimizing webapps in Lisp
Clojure: Programming self-optimizing webapps in Lisp
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of Presto
 
Scaling Prometheus Metrics in Kubernetes with Telegraf | Chris Goller | Influ...
Scaling Prometheus Metrics in Kubernetes with Telegraf | Chris Goller | Influ...Scaling Prometheus Metrics in Kubernetes with Telegraf | Chris Goller | Influ...
Scaling Prometheus Metrics in Kubernetes with Telegraf | Chris Goller | Influ...
 
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
 
Meetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaCMeetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaC
 
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
 
Break up the Monolith: Testing Microservices
Break up the Monolith: Testing MicroservicesBreak up the Monolith: Testing Microservices
Break up the Monolith: Testing Microservices
 
Перехват функций (хуки) под Windows в приложениях с помощью C/C++
Перехват функций (хуки) под Windows в приложениях с помощью C/C++Перехват функций (хуки) под Windows в приложениях с помощью C/C++
Перехват функций (хуки) под Windows в приложениях с помощью C/C++
 
Big Decimal: Avoid Rounding Errors on Decimals in JavaScript
Big Decimal: Avoid Rounding Errors on Decimals in JavaScriptBig Decimal: Avoid Rounding Errors on Decimals in JavaScript
Big Decimal: Avoid Rounding Errors on Decimals in JavaScript
 
Functional programming, TypeScript and RXJS
Functional programming, TypeScript and RXJSFunctional programming, TypeScript and RXJS
Functional programming, TypeScript and RXJS
 
On component interface
On component interfaceOn component interface
On component interface
 

Más de Pramati Technologies

Graph db - Pramati Technologies [Meetup]
Graph db - Pramati Technologies [Meetup]Graph db - Pramati Technologies [Meetup]
Graph db - Pramati Technologies [Meetup]Pramati Technologies
 
Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]Pramati Technologies
 
Adaptive Cards - Pramati Technologies
Adaptive Cards - Pramati TechnologiesAdaptive Cards - Pramati Technologies
Adaptive Cards - Pramati TechnologiesPramati Technologies
 
VitaFlow | Mageswaran Dhandapani [Pramati]
VitaFlow | Mageswaran Dhandapani [Pramati]VitaFlow | Mageswaran Dhandapani [Pramati]
VitaFlow | Mageswaran Dhandapani [Pramati]Pramati Technologies
 
Typography Style Transfer using GANs | Pramati
Typography Style Transfer using GANs | Pramati Typography Style Transfer using GANs | Pramati
Typography Style Transfer using GANs | Pramati Pramati Technologies
 
Document Clustering using LDA | Haridas Narayanaswamy [Pramati]
Document Clustering using LDA | Haridas Narayanaswamy [Pramati]Document Clustering using LDA | Haridas Narayanaswamy [Pramati]
Document Clustering using LDA | Haridas Narayanaswamy [Pramati]Pramati Technologies
 
Pramati - Chennai Development Center
Pramati - Chennai Development CenterPramati - Chennai Development Center
Pramati - Chennai Development CenterPramati Technologies
 

Más de Pramati Technologies (7)

Graph db - Pramati Technologies [Meetup]
Graph db - Pramati Technologies [Meetup]Graph db - Pramati Technologies [Meetup]
Graph db - Pramati Technologies [Meetup]
 
Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]
 
Adaptive Cards - Pramati Technologies
Adaptive Cards - Pramati TechnologiesAdaptive Cards - Pramati Technologies
Adaptive Cards - Pramati Technologies
 
VitaFlow | Mageswaran Dhandapani [Pramati]
VitaFlow | Mageswaran Dhandapani [Pramati]VitaFlow | Mageswaran Dhandapani [Pramati]
VitaFlow | Mageswaran Dhandapani [Pramati]
 
Typography Style Transfer using GANs | Pramati
Typography Style Transfer using GANs | Pramati Typography Style Transfer using GANs | Pramati
Typography Style Transfer using GANs | Pramati
 
Document Clustering using LDA | Haridas Narayanaswamy [Pramati]
Document Clustering using LDA | Haridas Narayanaswamy [Pramati]Document Clustering using LDA | Haridas Narayanaswamy [Pramati]
Document Clustering using LDA | Haridas Narayanaswamy [Pramati]
 
Pramati - Chennai Development Center
Pramati - Chennai Development CenterPramati - Chennai Development Center
Pramati - Chennai Development Center
 

Último

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesThousandEyes
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform EngineeringJemma Hussein Allen
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...Sri Ambati
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsVlad Stirbu
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...Product School
 

Último (20)

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 

Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies

  • 1. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Clojure through the eyes of a Java Nut Kannan Ramamoorthy Principal Engineer
  • 2. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● (Used to be) A strong believer that “OOPS is a natural way to design real- world problems.” ● (Used to) Read & chat a lot about Java and Spring with fellow Java developers. ● Still a Java developer. ● Not a ‘Know-it-all’ Clojure guy. Hence, one among the Java user tribe. About Me: 2 2
  • 3. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Not a Clojure vs Java comparison. ● Not a Clojure Tutorial. ● Probably won’t be able to use/try Clojure right away. ● My personal experience on how it ‘feels’ to use Clojure. ● Throw light on Clojure world. 3 3
  • 4. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer ● Amusing Parts ● Hard parts ● Gotchas ● Questions 4 4
  • 5. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer - [About,..] ● Amusing Parts ● Hard parts ● Gotchas ● Questions 5 5
  • 6. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● A dynamically typed ● Functional programming language ● Lisp family ● Runs on JVM ● 100% Java Clojure Primer - About: 6 6
  • 7. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer - [About, Syntax...] ● Amusing Parts ● Hard parts ● Gotchas ● Questions 7 7
  • 8. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. (operator <operand1> <operand2> ..) Clojure Primer - (Over)simplified Syntax: 8 8 Special construct/Function/Macro
  • 9. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Special construct: Built in language constructs. Function: Functions that can be defined by us. Equivalent to Java’s methods. Macro: #Later Clojure Primer - Definitions: 9 9
  • 10. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer - [About, Syntax, Evaluation Model] ● Amusing Parts ● Hard parts ● Gotchas ● Questions 10 10
  • 11. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Clojure Primer - (Over)simplified Evaluation model: 11 11
  • 12. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer ● Amusing Parts ● Hard parts ● Gotchas ● Questions 12 12
  • 13. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer ● Amusing Parts ● Hard parts ● Gotchas ● Questions 13 13
  • 14. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● As mentioned in primer, (operator <argument1> <argument2> ..) Examples, Simple Syntax: 14 14 Expression Meaning (+ 1 2) 'Add' 1 and 2. (= v1 v2) 'Equality check' for values of 'v1' and 'v2'. (ns new-name-space) 'Switches namespace' to “new- name-space”. (Namespace is equivalent to Java’s package)
  • 15. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Expression Meaning (println “Test String”) 'Prints' the given string. (def v 1) 'Define' a variable ‘v’ with value 1 (in the current namespace) (defn prn [x] (prinln x)) 'Define' a function named 'prn' that accepts a parameter and prints it. Simple Syntax (cont..): 15 15
  • 16. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Less Special Constructs: 16 16 ● Special constructs are the basic building blocks of a language. ● Provided the special constructs, you will be able to build the whole language yourself. ● If you wish, you could define the whole language by yourself.
  • 17. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Less Special Constructs (cont..): 17 17
  • 18. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. We can definition of short-circuit or (||) as below,. (defmacro || "Equivalent of or" ([] nil) ([expr] `~expr) ([expr & other-exprs] `(let [val# (|| ~expr)] (if val# val# (|| ~@other-exprs))))) Less Special Constructs (cont..): 18 18
  • 19. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Infinite/lazy sequence 19 19 (print (take 2 (list 0 1 2 3 4))) ; (0 1) (print (take 2 (range))) ; (0 1) (print (take 10 (range))) ; (0 1 2 3 4 5 6 7 8 9) (print (take 1000000 (range))) ; Prints first 1M numbers
  • 20. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Lazy sequences are common in Clojure. ● (Most of the cases) normal sequence can be replaced with lazy sequence, helps in deferring the computation until its needed. Infinite/lazy sequence (cont...) 20 20
  • 21. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Introducing 2 new construct before going into detail. List (list 1 2 “three”) ; This creates a list with elements 1, 2 and “three” In short-form the above notation can be written as, ‘(1 2 “three”) Program as Data: 21 21
  • 22. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Quote (quote (+ 1 2)) ; Returns the expression as is, i.e., (+ 1 2) In short form this can be written as, ‘(+ 1 2) Program as Data (cont...): 22 22
  • 23. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Does that ring a bell? ● After seeing the below Clojure snippets? (print “string”) (take 2 (list 1 2 3)) ● Isn’t the above code looks like a list without quote? ● All the Clojure programs are just nested list (Homoiconicity). Program as Data (cont...): 23 23
  • 24. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Lets you create DSL or custom syntactic abstraction without having to be wait for language support. ● Things like ‘Enhanced switch’ in Java 13 doesn’t excite you much. You can write it yourself if you want. ● For ex, you can define a macro that can be used like this which ends up adding the numbers that you specify. (evaluate add "1,2,3 and 4") Macros (revisited): 24 24
  • 25. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Lets you do CSP (Communicating Sequential Process) style programming. ● Defines threads as go -blocks and channels for inter- communication. ● Comparable to ‘Thread’ communicating with blocking queues in Java. ● Special highlight feature (alts!!), which lets you wait on multiple channels. (alts!! [channel1 channel2 channel3]) core.async (CSP) : 25 25
  • 26. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● CLP - let’s you define the constraint of your problem and one or generic algorithms solve the problem for you. ● At a high-level, you say “what is your problem?” the framework will figure out “how to solve it?” ● Classical applications, “n-queens”, “sudoku”, “Timetable creation”, etc. core.logic (CLP): 26 26
  • 27. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. core.logic (CLP) - example: 27 27
  • 28. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Lets you write a sophisticated switch-case style matching. Example, (match [x y z] [_ 1 2] 1 [1 2 _ ] 2 [_ _ 1] 3 [_ _ 2] 4 :else 5) core.match: 28 28
  • 29. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Has a Isomorphic counterpart ClojureScript (CLJS) ● Write Clojure that can be compiled to Javascript. ● Lets you code make use of all the goodness of Clojure for browser. Isomorphic: 29 29
  • 30. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Less verbose, short and sweet code. ● Powered by syntactic abstractions and abstract, reusable functions definitions. ● Some examples…. Conciseness: 30 30
  • 31. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Cartesian product: (for [x '(1 2 3) y '(1 2 3)] [x y]) ;; Return ([1 1] [1 2] [1 3] [2 1] [2 2] [2 3] [3 1] [3 2] [3 3]) Conciseness example: 31 31
  • 32. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Reading a file: (slurp "/Users/me/sample.txt") (slurp "https://google.com") (slurp "ftp://localhost:2121/sample.txt") Conciseness example: 32 32
  • 33. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Fibonacci solution that you can tweet: (def fib (lazy-cat [0 1] (map + (rest fib) fib))) (take 10 fib) ; Prints (0 1 1 2 3 5 8 13 21 34) Conciseness example: 33 33
  • 34. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Wrap your function so that the result of the function is cached for a given parameter and returned on consecutive call. ● Reusable a caching implementation that can wrap any applicable functions. ● ‘Referential Transparency’ of most of the functions makes it easy to memoize it. Memoization: 34 34
  • 35. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● With all the goodness of Clojure, you can also have access to the ocean of Java library. (println (System/currentTimeMillis)) ; prints Current time in milliseconds. (doto (new java.util.HashMap) (.put "one" 1) (.put "two" 2)) ; Calls put(“one”, 1) and put(“two”,2) ; a new hashmap. Java Interop: 35 35
  • 36. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer ● Amusing Parts ● Hard parts ● Gotchas ● Questions 36 36
  • 37. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer ● Amusing Parts ● Hard parts ● Gotchas ● Questions 37 37
  • 38. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Parentheses is not arbitrary as in Java, ex, (+ 1 2 3) cannot be written as (+ 1 (2 3)) ● Naturally, takes some time to adopt for Java developers. Usage of parentheses: 38 38
  • 39. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Understand that each parentheses is a unquoted list and the first element is expected to be an operand. ● Use an IDE to have the code properly formatted. Overcoming - Usage of parentheses: 39 39
  • 40. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Shift to s-expression: ● Mental shift to expressions of style (operator operand1 operand2)especially for the operators where order matters. Example, (> 2 1) ; Checks if 2 is greater than 1 (< 1 2) ; Checks if 1 is less than 2 40 40
  • 41. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Unlearn the conventional meaning and read the docs for the operators. Meanings for operators in Clojure may slightly differ. Ex, > means if the following numbers are in descending order < means if the following numbers are in ascending order ● Practice Overcoming s-expression shift: 41 41
  • 42. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● All the Clojure’s core data structures are immutable. ● One of the MOST DIFFICULT part for a Java developer. Immutable Data Structures: 42 42
  • 43. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Don’t go with the easy ways of working around with immutable types. ● We naturally think using loops. Rather practice using map, reduce and recursion. Overcoming difficulty with Immutable Data Structures: 43 43
  • 44. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● It takes time to get the significance of Macro. ● Having not used to meta-programming, choice of when to use macro will be challenging. ● Understanding the scope of variables used in execution for a Macro will be difficult. Programming with Macro: 44 44
  • 45. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Try implementing the out-of-box macros as functions and see if it is possible. ● Using Macro for syntactic abstraction is a good choice. For everything else ● WRT the scope, getting mental model of 2-level of execution helps. ● Practice. Overcoming Macro usage difficulty: 45 45
  • 46. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. ● Lazy sequence itself is hard to imagine initially. ● Implementing one by yourself also bit hard initially. Overcoming: Understand, the power of lazy sequence is the implementation of the consumer. Try understand how it works and try solving it. Lazy sequence: 46 46
  • 47. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer ● Amusing Parts ● Hard parts ● Gotchas ● Questions 47 47
  • 48. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer ● Amusing Parts ● Hard parts ● Gotchas ● Questions 48 48
  • 49. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Question: You say core data structures are not mutable. So how a very basic use case of addition or deletion of the element from a data structure is addressed? Gotchas: 49 49
  • 50. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Answer: Clojure does support those operations. But it doesn’t change the original data structure. For ex, (def a [1 2]) ; Define a vector with 1,2 (println (conj a 3)) ; Append 3 to it ;; Prints [1 2 3] (println a) ;; Prints [1 2] Gotchas: 50 50
  • 51. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Question: What?! Do you create a new collection for each change that we do? Aren’t you filling up the memory unnecessarily? Gotchas: 51 51
  • 52. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Answer: Nope. Clojure uses a mechanism called Persistent Data structure, which doesn’t actually create a new object but reuses the existing one and still having the variables immutable. Gotchas: 52 52
  • 53. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Question: It is nice that the programs are concise. But anyhow, under the hood it boils down to so many lines of Java code? What is so nice about conciseness? Gotchas: 53 53
  • 54. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. Answer: ● Programming with less code could probably means more productivity. ● But surely means less testing, if you are building on top of existing and pre-tested code. In that way, conciseness matters. Gotchas: 54 54
  • 55. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer ● Amusing Parts ● Hard parts ● Gotchas ● Questions 55 55
  • 56. Private and confidential. Copyright (C) 2018, Pramati Technologies. All rights reserved. This Talk? ● Clojure Primer ● Amusing Parts ● Hard parts ● Gotchas ● Questions 56 56