SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
Clojure 1.1 and
    Beyond
Deprecations
  watchers
  add-classpath
  ^
  clojure.parallel
  clojure.lang.Repl, clojure.lang.Script
Watchers
Functions add-watcher and remove-watcher are gone.

Replaced by add-watch and remove-watch.
(def x (ref 0))

(add-watch x :change (fn [key r old new]
                       (println old " -> " new)))

(dosync (alter x inc))
; 0 -> 1
;=> 1

(remove-watch x :change)
(dosync (alter x inc))
;=> 2
                                                     highlight: clojure
add-classpath
Used to be able to do insane things like:
(add-classpath "http://github.com/fogus/polyglot/raw/master/reading/onlisp/")
(require '[prolog :as pro])
(pro/fact painter reynolds joshua english)
(pro/db-query 'painter)
;=> ((reynolds joshua english))
                                                                                highlight: clojure


You should feel unclean by this.

^
Deprecated, use meta instead:
(def x (with-meta [1 2] {:in-love? true}))
^x
;=> {:in-love? true}

(meta x)
;=> {:in-love? true}
                                                                                highlight: clojure


This is so that ^ can eventually become the type hint reader macro.
clojure.parallel
clojure.parallelis being re-worked to use the Java 7 fork-join library. You can
track progress or contribute on Clojure's par branch.

http://github.com/richhickey/clojure/tree/par

REPL and Scripts
clojure.lang.Repl           and clojure.lang.Script have been replaced by clojure.main.
java   -cp   clojure.jar   clojure.main                      #   REPL
java   -cp   clojure.jar   clojure.main   -i script.clj -r   #   REPL, load script.clj on startup
java   -cp   clojure.jar   clojure.main   script.clj         #   Run script
java   -cp   clojure.jar   clojure.main   -e '(+ 1 41)'      #   Eval string
java   -cp   clojure.jar   clojure.main   -                  #   Run with stdin
                                                                                            highlight: clojure
Additions
  Primitive Array Generation and Casting
  Chunked Sequences
  Futures
  Promises
  Transients
  Function pre- and post- conditions
  User-controlled Thread Bindings (not discussed)
  Ref History (not discussed)
  New Namespaces
  Miscellaneous
Primitive Array Generation
boolean-array, byte-array, char-array,        and short-array
(def x (byte-array [(byte 0x71) (byte 0x75) (byte 0x78)]))
(String. x)
;=> "qux"
                                                                highlight: clojure



Primitive Array Casting
booleans, bytes, chars, shorts
Chunked Sequences
Making sequence operations more efficient since v1.1!

What is the Granularity of Laziness and Sequential Processing?

Prior to 1.1 the answer was 1 element at a time.




For 1.1 and beyond the answer is 1 chunk at a time.
A Chunk at a Time
Advantages of Chunkiness
    Still works on the 1-at-a-time model
    Aligns with the underlying data structures
    Amortizes the overhead of sequential access
          Once every 32 times
    Still avoids full realization

Disadvantage
    Eliminates full laziness
         Although an API for 1-at-a-time laziness is in the works

More Information
http://bit.ly/chunked
Futures
Asynchronous computations occuring in other threads that will block if the
expression has not finished. All subsequent dereferencing will return the
calculated value.
(let [x (future (do (Thread/sleep 5000) (+ 41 1)))]
  @x) ; ... 5 seconds later
;=> 42
                                                                       highlight: clojure


Also useful: future-call, future?, future-done?, future-cancel, future-cancelled?.

Promise / Deliver
A hand-off reference used to deliver a value from one thread to another. Any
attempt to dereference will block until "delivery".
(def x (promise))
(.start (Thread. #(do (Thread/sleep 5000) (deliver x "Dear John"))))
@x
; ... 5 seconds later
;=> "Dear John"
                                                                       highlight: clojure
Transients
Provides a mutable subset of functions to use on transient versions of the
standard collection types.

     Used on locals only and only on vectors, hash-maps, and hash-sets
     Support the read-only functions
     transient, persistent!, conj!, assoc!, dissoc!, pop!, disj! to mutate
     Thread-safe. Modification attempt in a different thread throws an execption

Here is a transient version of concat:
(defn zen-cat [x y]
  (loop [src y, ret (transient x)]
    (if src
      (recur (next src) (conj! ret (first src)))
      (persistent! ret))))

(zen-cat [1 2 3] [4 5 6])
;=> [1 2 3 4 5 6]
                                                                                   highlight: clojure


Rememeber to call persistent! before returning your transient only if you
intend to give out a mutable version:
(persistent! (conj! (zen-cat [1 2 3] [4 5 6]) 7))   ;; assume just ret on return
;=> [1 2 3 4 5 6 7]
                                                                                   highlight: clojure
:pre and :post
Sets constraints on the input and output of a function.
(defn constrained-fn [f x]
  {:pre [(pos? x)]
   :post [(= % (* 2 x))]}
  (f x))

(constrained-fn #(* 2 %) 2)
;=> 4

(constrained-fn #(* 2 %) -2)
; java.lang.AssertionError: Assert failed: (pos? x)

(constrained-fn #(* 3 %) 2)
; java.lang.AssertionError: Assert failed: (= % (* 2 x))
                                                           highlight: clojure
New Namespaces
  clojure.test
  clojure.test.junit
  clojure.stacktrace
  clojure.walk
  clojure.template
Misc.
juxt

((juxt a b c) x) => [(a x) (b x) (c x)]

((juxt + *))
;=> [0 1]

((juxt - /) 2)
;=> [-2 1/2]
                                          highlight: clojure
Clojure 1.2 (probably)
   reify
   deftype
   defprotocol
   Fine-grained locals clearing
   Agent error handlers

Clojure 1.?
   Clojure in Clojure
   IO streams (not discussed)
   Chunked sequence API (not discussed)
   Program verification via Datalog (not discussed)
   Finger trees (read The Joy of Clojure)
Reify -- aka newnew
Like proxy, except:

    Only protocols or interfaces
    Method bodies are true methods and not external functions
         No dynamic swapping of methods
    Must be AOT'd

Deftype
    Dynamically generates bytecode for an anonymous class with some fields and a type slot
    Might also generate methods for protocols or interfaces
    Can be AOT'd for extra benefits

Like defstruct, except:

    Generates a class with fields, no map lookups
    Faster field lookup
    Has a proper type slot
    Fields can be primitive and hinted
    Can implement any number of protocols or interfaces

More Information
http://bit.ly/clj-types
Protocols
The best of interfaces

    Signatures only
    Multiple implements

Without the mold
    Which interfaces to implement are defined along with the type
    Avoids isa/instanceof and heirarchies

And Even Better
    Allows independent extension
    Single dispatch on type

More Information

http://bit.ly/clj-protocols
Fine-grained Locals Clearing
(let [r (range 1e9)] [(first r) (last r)])
; java.lang.OutOfMemoryError: Java heap space
                                                highlight: clojure


No need for strict tail-position adherence!

More Information
http://bit.ly/luz-ur-head
Agent Error Queues
Since agent actions are run in other thread(s), what happens if exceptions are
thrown?

Currently
Exceptions are stored in the agent itself and accessed/cleared by agent-
errors/ clear-agent-errors

Future
Callbacks provided a queue of errors and react based on :continue and :fail
error modes

More information

http://bit.ly/clj-aeh
Clojure in Clojure (cinc)
Clojure is three parts:

 1. The compiler -- JAVA
 2. The data structures -- JAVA (mostly)
 3. clojure.core+ -- CLOJURE

Clojure in Clojure is the effort to replace the Java bits above with Clojure
without losing the JVM.
Toward Clojure in Clojure
  reify   is of the utmost importance

      We could use proxy and gen-class but too slow

  The compiler and reader could be written in Clojure today
      But first types and protocols should be rolled out
Why Clojure in Clojure?
    Porting
        No need to port the structures
        Only (relatively) tiny bits of the compiler
             Description of Clojure's special forms
        Using the JVM to bootstrap other platform targets

But What is Clojure?
Too philosophical for this talk.

More Information
http://blog.n01se.net/?p=41
Questions?




http://joyofclojure.com

http://manning.com/fogus

Order today with code 'j1337' and get a whopping 37% off!

Weitere ähnliche Inhalte

Was ist angesagt?

What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2Zaar Hai
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.Mike Fogus
 
betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
betterCode() Go: Einstieg in Go, Standard-Library und ÖkosystembetterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
betterCode() Go: Einstieg in Go, Standard-Library und ÖkosystemJan Stamer
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascriptReece Carlson
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
そうだ、bf処理系作ろう!もちろんSQLで!
そうだ、bf処理系作ろう!もちろんSQLで!そうだ、bf処理系作ろう!もちろんSQLで!
そうだ、bf処理系作ろう!もちろんSQLで!bleis tift
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)Jacek Laskowski
 
Advanced python
Advanced pythonAdvanced python
Advanced pythonEU Edge
 
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-EntwicklerJavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-EntwicklerJan Stamer
 
Functional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heavenFunctional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heavenPawel Szulc
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersAppier
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)ujihisa
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talkJohn Stevenson
 
JavaOne 2013 - Clojure for Java Developers
JavaOne 2013 - Clojure for Java DevelopersJavaOne 2013 - Clojure for Java Developers
JavaOne 2013 - Clojure for Java DevelopersJan Kronquist
 
The Macronomicon
The MacronomiconThe Macronomicon
The MacronomiconMike Fogus
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - StockholmJan Kronquist
 

Was ist angesagt? (20)

What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2
 
Groovy!
Groovy!Groovy!
Groovy!
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
 
betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
betterCode() Go: Einstieg in Go, Standard-Library und ÖkosystembetterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascript
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
そうだ、bf処理系作ろう!もちろんSQLで!
そうだ、bf処理系作ろう!もちろんSQLで!そうだ、bf処理系作ろう!もちろんSQLで!
そうだ、bf処理系作ろう!もちろんSQLで!
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
Advanced python
Advanced pythonAdvanced python
Advanced python
 
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-EntwicklerJavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
 
Functional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heavenFunctional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heaven
 
Sdl Basic
Sdl BasicSdl Basic
Sdl Basic
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python Programmers
 
System Calls
System CallsSystem Calls
System Calls
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
 
JavaOne 2013 - Clojure for Java Developers
JavaOne 2013 - Clojure for Java DevelopersJavaOne 2013 - Clojure for Java Developers
JavaOne 2013 - Clojure for Java Developers
 
The Macronomicon
The MacronomiconThe Macronomicon
The Macronomicon
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 

Andere mochten auch

tools and machines
tools and machinestools and machines
tools and machinesTy
 
Independencia judicial
Independencia judicialIndependencia judicial
Independencia judicialeric prado
 
Powerpoint For Linked In
Powerpoint For Linked InPowerpoint For Linked In
Powerpoint For Linked Incyndilevy
 

Andere mochten auch (7)

Magazine Ad
Magazine AdMagazine Ad
Magazine Ad
 
tools and machines
tools and machinestools and machines
tools and machines
 
Morner - What You See Is What You Get
Morner - What You See Is What You GetMorner - What You See Is What You Get
Morner - What You See Is What You Get
 
Why Scala?
Why Scala?Why Scala?
Why Scala?
 
Launch Promo
Launch PromoLaunch Promo
Launch Promo
 
Independencia judicial
Independencia judicialIndependencia judicial
Independencia judicial
 
Powerpoint For Linked In
Powerpoint For Linked InPowerpoint For Linked In
Powerpoint For Linked In
 

Ähnlich wie Clojure 1.1 And Beyond

Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with ClojureJohn Stevenson
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lispelliando dias
 
Clojure concurrency
Clojure concurrencyClojure concurrency
Clojure concurrencyAlex Navis
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019Leonardo Borges
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the webMichiel Borkent
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015Michiel Borkent
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring ClojurescriptLuke Donnet
 
Clojure and Modularity
Clojure and ModularityClojure and Modularity
Clojure and Modularityelliando dias
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Pythonkwatch
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)tarcieri
 
Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»DataArt
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 

Ähnlich wie Clojure 1.1 And Beyond (20)

Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
 
Clojure concurrency
Clojure concurrencyClojure concurrency
Clojure concurrency
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Clojure and Modularity
Clojure and ModularityClojure and Modularity
Clojure and Modularity
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Clojure+ClojureScript Webapps
Clojure+ClojureScript WebappsClojure+ClojureScript Webapps
Clojure+ClojureScript Webapps
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)
 
Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Lobos Introduction
Lobos IntroductionLobos Introduction
Lobos Introduction
 

Mehr von Mike Fogus

Introduction to Zeder - a production rules toolkit for Clojure
Introduction to Zeder - a production rules toolkit for ClojureIntroduction to Zeder - a production rules toolkit for Clojure
Introduction to Zeder - a production rules toolkit for ClojureMike Fogus
 
The Shape of Functional Programming
The Shape of Functional ProgrammingThe Shape of Functional Programming
The Shape of Functional ProgrammingMike Fogus
 
ClojureScript Anatomy
ClojureScript AnatomyClojureScript Anatomy
ClojureScript AnatomyMike Fogus
 
The Return of the Living Datalog
The Return of the Living DatalogThe Return of the Living Datalog
The Return of the Living DatalogMike Fogus
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureMike Fogus
 

Mehr von Mike Fogus (6)

Introduction to Zeder - a production rules toolkit for Clojure
Introduction to Zeder - a production rules toolkit for ClojureIntroduction to Zeder - a production rules toolkit for Clojure
Introduction to Zeder - a production rules toolkit for Clojure
 
The Shape of Functional Programming
The Shape of Functional ProgrammingThe Shape of Functional Programming
The Shape of Functional Programming
 
Confo
ConfoConfo
Confo
 
ClojureScript Anatomy
ClojureScript AnatomyClojureScript Anatomy
ClojureScript Anatomy
 
The Return of the Living Datalog
The Return of the Living DatalogThe Return of the Living Datalog
The Return of the Living Datalog
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of Clojure
 

Kürzlich hochgeladen

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Kürzlich hochgeladen (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Clojure 1.1 And Beyond

  • 2. Deprecations watchers add-classpath ^ clojure.parallel clojure.lang.Repl, clojure.lang.Script
  • 3. Watchers Functions add-watcher and remove-watcher are gone. Replaced by add-watch and remove-watch. (def x (ref 0)) (add-watch x :change (fn [key r old new] (println old " -> " new))) (dosync (alter x inc)) ; 0 -> 1 ;=> 1 (remove-watch x :change) (dosync (alter x inc)) ;=> 2 highlight: clojure
  • 4. add-classpath Used to be able to do insane things like: (add-classpath "http://github.com/fogus/polyglot/raw/master/reading/onlisp/") (require '[prolog :as pro]) (pro/fact painter reynolds joshua english) (pro/db-query 'painter) ;=> ((reynolds joshua english)) highlight: clojure You should feel unclean by this. ^ Deprecated, use meta instead: (def x (with-meta [1 2] {:in-love? true})) ^x ;=> {:in-love? true} (meta x) ;=> {:in-love? true} highlight: clojure This is so that ^ can eventually become the type hint reader macro.
  • 5. clojure.parallel clojure.parallelis being re-worked to use the Java 7 fork-join library. You can track progress or contribute on Clojure's par branch. http://github.com/richhickey/clojure/tree/par REPL and Scripts clojure.lang.Repl and clojure.lang.Script have been replaced by clojure.main. java -cp clojure.jar clojure.main # REPL java -cp clojure.jar clojure.main -i script.clj -r # REPL, load script.clj on startup java -cp clojure.jar clojure.main script.clj # Run script java -cp clojure.jar clojure.main -e '(+ 1 41)' # Eval string java -cp clojure.jar clojure.main - # Run with stdin highlight: clojure
  • 6. Additions Primitive Array Generation and Casting Chunked Sequences Futures Promises Transients Function pre- and post- conditions User-controlled Thread Bindings (not discussed) Ref History (not discussed) New Namespaces Miscellaneous
  • 7. Primitive Array Generation boolean-array, byte-array, char-array, and short-array (def x (byte-array [(byte 0x71) (byte 0x75) (byte 0x78)])) (String. x) ;=> "qux" highlight: clojure Primitive Array Casting booleans, bytes, chars, shorts
  • 8. Chunked Sequences Making sequence operations more efficient since v1.1! What is the Granularity of Laziness and Sequential Processing? Prior to 1.1 the answer was 1 element at a time. For 1.1 and beyond the answer is 1 chunk at a time.
  • 9. A Chunk at a Time
  • 10. Advantages of Chunkiness Still works on the 1-at-a-time model Aligns with the underlying data structures Amortizes the overhead of sequential access Once every 32 times Still avoids full realization Disadvantage Eliminates full laziness Although an API for 1-at-a-time laziness is in the works More Information http://bit.ly/chunked
  • 11. Futures Asynchronous computations occuring in other threads that will block if the expression has not finished. All subsequent dereferencing will return the calculated value. (let [x (future (do (Thread/sleep 5000) (+ 41 1)))] @x) ; ... 5 seconds later ;=> 42 highlight: clojure Also useful: future-call, future?, future-done?, future-cancel, future-cancelled?. Promise / Deliver A hand-off reference used to deliver a value from one thread to another. Any attempt to dereference will block until "delivery". (def x (promise)) (.start (Thread. #(do (Thread/sleep 5000) (deliver x "Dear John")))) @x ; ... 5 seconds later ;=> "Dear John" highlight: clojure
  • 12. Transients Provides a mutable subset of functions to use on transient versions of the standard collection types. Used on locals only and only on vectors, hash-maps, and hash-sets Support the read-only functions transient, persistent!, conj!, assoc!, dissoc!, pop!, disj! to mutate Thread-safe. Modification attempt in a different thread throws an execption Here is a transient version of concat: (defn zen-cat [x y] (loop [src y, ret (transient x)] (if src (recur (next src) (conj! ret (first src))) (persistent! ret)))) (zen-cat [1 2 3] [4 5 6]) ;=> [1 2 3 4 5 6] highlight: clojure Rememeber to call persistent! before returning your transient only if you intend to give out a mutable version: (persistent! (conj! (zen-cat [1 2 3] [4 5 6]) 7)) ;; assume just ret on return ;=> [1 2 3 4 5 6 7] highlight: clojure
  • 13. :pre and :post Sets constraints on the input and output of a function. (defn constrained-fn [f x] {:pre [(pos? x)] :post [(= % (* 2 x))]} (f x)) (constrained-fn #(* 2 %) 2) ;=> 4 (constrained-fn #(* 2 %) -2) ; java.lang.AssertionError: Assert failed: (pos? x) (constrained-fn #(* 3 %) 2) ; java.lang.AssertionError: Assert failed: (= % (* 2 x)) highlight: clojure
  • 14. New Namespaces clojure.test clojure.test.junit clojure.stacktrace clojure.walk clojure.template
  • 15. Misc. juxt ((juxt a b c) x) => [(a x) (b x) (c x)] ((juxt + *)) ;=> [0 1] ((juxt - /) 2) ;=> [-2 1/2] highlight: clojure
  • 16. Clojure 1.2 (probably) reify deftype defprotocol Fine-grained locals clearing Agent error handlers Clojure 1.? Clojure in Clojure IO streams (not discussed) Chunked sequence API (not discussed) Program verification via Datalog (not discussed) Finger trees (read The Joy of Clojure)
  • 17. Reify -- aka newnew Like proxy, except: Only protocols or interfaces Method bodies are true methods and not external functions No dynamic swapping of methods Must be AOT'd Deftype Dynamically generates bytecode for an anonymous class with some fields and a type slot Might also generate methods for protocols or interfaces Can be AOT'd for extra benefits Like defstruct, except: Generates a class with fields, no map lookups Faster field lookup Has a proper type slot Fields can be primitive and hinted Can implement any number of protocols or interfaces More Information http://bit.ly/clj-types
  • 18. Protocols The best of interfaces Signatures only Multiple implements Without the mold Which interfaces to implement are defined along with the type Avoids isa/instanceof and heirarchies And Even Better Allows independent extension Single dispatch on type More Information http://bit.ly/clj-protocols
  • 19. Fine-grained Locals Clearing (let [r (range 1e9)] [(first r) (last r)]) ; java.lang.OutOfMemoryError: Java heap space highlight: clojure No need for strict tail-position adherence! More Information http://bit.ly/luz-ur-head
  • 20. Agent Error Queues Since agent actions are run in other thread(s), what happens if exceptions are thrown? Currently Exceptions are stored in the agent itself and accessed/cleared by agent- errors/ clear-agent-errors Future Callbacks provided a queue of errors and react based on :continue and :fail error modes More information http://bit.ly/clj-aeh
  • 21. Clojure in Clojure (cinc) Clojure is three parts: 1. The compiler -- JAVA 2. The data structures -- JAVA (mostly) 3. clojure.core+ -- CLOJURE Clojure in Clojure is the effort to replace the Java bits above with Clojure without losing the JVM.
  • 22. Toward Clojure in Clojure reify is of the utmost importance We could use proxy and gen-class but too slow The compiler and reader could be written in Clojure today But first types and protocols should be rolled out
  • 23. Why Clojure in Clojure? Porting No need to port the structures Only (relatively) tiny bits of the compiler Description of Clojure's special forms Using the JVM to bootstrap other platform targets But What is Clojure? Too philosophical for this talk. More Information http://blog.n01se.net/?p=41