Professional Documents
Culture Documents
Java 7 :- JSR 292: Supporting Dynamically Typed Languages on the JavaTM Platform MLVM Multi Language Virtual Machine.
Alonzo Church
Creator of -Calculus 1940
(H). H is defined as the function that always returns the identity function. That is, (Hx) is I for whatever x may be.
8
Functional Programming
Derives from mathematics, Lambda Calculus
Erlang -
Massively scalable soft real-time systems with requirements on high availability and fault tolerant systems.
"We wanted to make Java more expressive, so people could be more productive" and write at a higher level of abstraction with fewer lines of code, Odersky says.
How it is scalable Getting Started
11
13
Scala Traits
It is an kind of an Interface with fields and concrete methods. Unlike Class inheritance, a class can mix (Mixins) in any number of traits.
class Person extends PolyglotProgrammer with PolyglotSpeaker {} val person = new Person println(person.polyProg) println(person.polySpeaker)
14
15
Groovy
Groovy is the closest to Java language.
17
20
Groovy DSL
DSL with the help of identity: The Context Method
Trade trade = new Trade() trade.identity { setOrderId(1) setOrderStatus(false) setEquityName("Fictious Inc") setQuantity(100) setPrice(17.25) }
21
22
Clojure Functional
Predominately Functional language
(defn name doc-string? attr-map? [params*] body) (defn helloworld [username] returns a String hello message (str Hello, username))
Dynamic Language
Resolves types at runtime
23
Clojure Homoiconicity
Representation of its own data structures and atomic values or more casually code-as-data and data-as-code
(defn average [numbers] (/ (apply + numbers) (count numbers)))
Stateless
This definition is a list of data structure containing symbols, values, vectors and another list consists of function body (+ 7 3) on REPL yields => (+ 7 3)
10
24
Clojure Homoiconicity
Data as Code Consider map
(def names {"Rich" "Hickey" "Martin" "Odersky"})
Clojure Functional
First Class Functions
Functions that always return the same result when passed the same arguments Functions exist as data (function value).
Higher Order Functions Take other functions as arguments or return a function as a result.
27
Clojure Collections
All of them are immutable, heterogeneous and persistent.
28
Clojure Sequences
In Clojure, all these data structures can be accessed through a single abstraction: the sequence (seq) Every aggregate data structure in Clojure can be viewed as a sequence (first {"Rich" "Hickey" "Martin" "Odersky"}) (rest {"Rich" "Hickey" "Martin" "Odersky"}) (cons [James" Gosling] {"Rich" "Hickey" "Martin" "Odersky"})
29
Clojure STM
Software Transactional Manager is the way to handle concurrency of mutable data in Clojure. STM is very optimistic. Alternative to lock based synchronization.
Mutual Exclusion
Every read and write that it is performing is in a log.
Onus is on reader which will commit to the shared memory in case no modifications are done during the time, else would re-execute the transaction.
30
Clojure STM
Mutable References
ref, deref or @ , ref-set, dosync Need to be explicit when mutable data is required. (def value (ref 100)) ref wraps and protects access to its internal state. Even to read, it needs to deref (deref value) or @value As the value is in STM
31
Clojure STM
STM provides similar transaction properties of a Database But STM handles in memory, so cant guarantee durability. Updates are atomic. If you update more than one ref in a transaction, the cumulative effect of all the updates will appear as a single instantaneous event to anyone not inside your transaction.
Stateless
Updates are consistent. Refs can specify validation functions. If any of these functions fail, the entire transaction will fail. Updates are isolated. Running transactions cannot see partially completed results from other transactions.
32
Clojure STM
Agents
Agents provide independent, asynchronous change of individual locations.
Agents are bound to a single storage location for their lifetime, and only allow mutation of that location (to a new state) to occur as a result of an action.
33
Polylingualism
Sapir-Whorf Hypothesis
References
Programming in Scala (Martin Odersky, Lex Spoon, Bill Venners) Clojure Programming (Chas Emerick, Brian Carper, Christophe Grand) Programming Clojure (Stuart Halloway) Well Gounded Java Developer (Benjamin Evans, Martin Verburg)
37
Thank you !
gmail mohanjune@gmail.com Stateless twitter @mohanjune
38