SlideShare une entreprise Scribd logo
1  sur  28
New Features in
   Clojure
    Rich Hickey
Overview
• Unified primitive semantics
• Map key equality
• Improved interaction between dynamic
  binding and thread pools
• Explicitly dynamic vars
• Primitive support in fns
• This is all work-in-progress!
Objective - Unify
          Semantics
• Unify primitive and boxed integer semantics
 • Currently, boxed integer arithmetic
    promotes to bigint as needed
 • Primitive arithmetic throws on overflow
 • Means that you always have to be explicit
    about primitives
   • difficulty with representation choices
   • incidental boxing changes meaning
Objective - Make Fast
 Numerics Simple
• Would like to have literal numbers be used
  as primitives when possible
 • Ditto primitive method returns
• Coercion and primitive ops currently for
  experts only
 • Easy to fail to optimize
Unified Integer Semantics
• The semantics of primitive longs, plus throw on
  overflow
  • This is the only semantic that works for both
    boxed and primitive
• For bigint arithmetic, specify bigint operands
 • new literal bigint format: 42N
• Polymorphic boxed numeric tower still in place
• bigints now contagious, no more auto-
  reductions
Numeric Features
• Literal numbers are now treated implicitly
  as primitives
  • Locals known to be numbers are
    automatically coerced to long or double
• More automatic conversions
 • int matches long, float matches double
• Consistent canonic integer boxing
 • If fits in long, is Long
Numeric Features
• longs also match ints, and doubles match floats
 • long->int is checked
• Can’t force boxed representation from
  primitive coercion:
  • was always a bug to presume otherwise
  • (class (int 42)) => Long
  • ditto boxed values coming from arrays of
    primitives, and primitive returns from
    interop
Auto-promotion
• No longer the default
• Still available explicitly
• ’ is now a constituent character (like #)
• +', -', *', inc', dec' do auto-promotion
 • never return primitives
 • Unless you need to work with arbitrary-
    precision integers where BigInt contagion
    is insufficient, there is no reason to use
    them.
Objective - Align Map
 Keys and Numeric =
• Users frustrated when insert with one key
  representation, lookup fails with another
• Use (type flexible) equivalence for map =
 • but narrow equiv, only same category
    numbers are =
  • so floats not = to integers
  • but == still available for that
• new clojure.lang.BigInt class
Map Key Equality
• Hash maps and sets now use = for keys
 • this will make maps and sets unify 42 and
    42N, since using =
• Will still use stricter .equals when calling
  through java.util interfaces
• Not there yet
 • this will require renaming
    Associative.containsKey, since semantics
    will now differ
Objective - Make Binding
  Work with Threads
 • When work is sent to thread-pool threads,
   e.g. via agent sends or future calls, the work
   isn't done with the same binding set as the
   invocation (without manual effort)
   • Yet that is often the expectation/desire
 • Makes transparent parallelization difficult
 • Current tools for propagating bindings are
   expensive
Binding Issues
• Intended to be used within one thread
• Don’t support a notion of task or unit of
  work crossing threads
• Unsafe if used between threads
 • thus, must be copied
 • i.e., new bindings created for subtask
    thread
Thread Issues
• Threads don’t align with work tree
• And when threads used for subtasks, not
  usually explicitly launched as children
 • thread pool threads (re-)used instead
• Need better notion of subtasks not aligned
  with thread stack
Shared Bindings
• Allow subtasks in thread pool threads to
  share bindings with parent task
• Make binding access safe from subtask threads
 • Add volatile semantics for binding values
 • Ensure vars only set! from binding thread
• Sharing bindings is extremely fast
 • Just use same (immutable) binding map in
    subtask thread
Binding Conveyance
• Bindings are now automatically shared with
  threads used for future calls and agent
  sends

  • and anything built on them, e.g. pmap
• This reroots the binding frame for thread
  pool thread prior to your work fn running
  • so bindings in work fn ‘win’
• Just works
Binding and Scopes
• Much of this work driven by needs of
  resource scopes
 • Natural fit for binding
 • But need same notion of task tree
 • and without conveyance, would have
    same thread problems/surprises as
    bindings
• Scopes work can now proceed
Objective - Pay for
      What You Use
• All defs currently create fully dynamically
  rebindable vars
• Incur cost for every access
 • Is it dynamically bound?
 • Is it unbound?
 • What’s the current value
• Yet most vars (defns) have rarely-changing
  values, never dynamically bound
Why Top Level Vars?
• Traditional context-bound dynamic
  variables, like *out* et al

• Dynamically bound fns can be used for
  error handling
• Replace fns with fixed versions
 • Doesn’t require rebinding
• Mutable globals
Be Explicit about
      Dynamic Intent
• Change default semantic from dynamically
  rebindable to not
• Must declare vars dynamic using
 • ^:dynamic metadata
 • or .setDynamic on manually created Vars
• Better for consumers
• Enables significant optimizations
Metadata Features

• New ^:keyword metadata
 • turns into ^{:keyword true}
• Metadata stacks - ^:dynamic ^:private foo
 • Merges rather than replaces
 • same as ^{:dynamic true :private true} foo
Remove Overhead
• Remove binding check from access to non-
  dynamics
• Remove bound check from normal access
 • instead return Unbound object
   • has the var as field, prints in toString
   • implements IFn and throws on any
      invoke, with good message
Presume Stability
• Replace via defn to fix bugs case still remains
 • infrequent, but would like to avoid pain of
    static (i.e., re-eval of caller code)
• Minimize overhead
 • cache var values in fn
 • global var rev, inc on any var alteration
 • check rev on fn entry and reload vars if
    changed
  • else use cached values
Objective - Support
Primitive Args/Returns
• Clojure supports primitive arithmetic
  locally, and primitives in deftype/defrecord
  • But not in fn arguments or returns
  • Means you can’t break up your logic, or
    write helper functions, without
    introducing boxing
Issues
• fn is specified by an interface (IFn), taking
  and returning Objects
  • fns must still satisfy that interface
• How will callers know about primitive
  params/return, and how to invoke?
  • Support ^long and ^double type hints on
    args/return
IFn$LOD...
• New set of single-method nested IFn
  interfaces
  • Corresponding to all combinations of
    Object/long/double, to arity 4
• Compiler will compile invokePrim methods
  in addition to IFn virtual invoke methods

• When compiling direct invocation of prim fn,
  compiler will look at arglists metadata and
  make call to invokePrim method

• var still contains IFn object for HOFs etc
More Features
• ^long and ^double hints supported on args
• hint for return goes on arg vector
 • e.g. (defn foo ^long [x] ...)
 • so supports multi-arity with varied returns
• Other reference type hints allowed as well
 • Just for hints, not enforced
Future Fns
• Primitive-taking fn interfaces open door to
  non-boxing HOFs
• One more step to dynamically typed, yet
  internally primitive, map and reduce

  • When combined with collections of
    primitives
  • and chunked seqs
Summary
• New features enable much faster code
• Unified semantics reduce complexity
 • all features are still available
   • auto-promotion is explicit
   • dynamic binding is explicit
• Optimization more automatic, less work, less
  subtle
• Pave the way for scopes and primitive HOFs

Contenu connexe

Tendances

What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
Virtual function and abstract class
Virtual function and abstract classVirtual function and abstract class
Virtual function and abstract classShweta Shah
 
Python Built-in Functions and Use cases
Python Built-in Functions and Use casesPython Built-in Functions and Use cases
Python Built-in Functions and Use casesSrajan Mor
 
XII Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-FunctionXII  Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-FunctionPrem Joel
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NETBlackRabbitCoder
 
Compositionality and Category Theory - a montage of slides/transcript for sec...
Compositionality and Category Theory - a montage of slides/transcript for sec...Compositionality and Category Theory - a montage of slides/transcript for sec...
Compositionality and Category Theory - a montage of slides/transcript for sec...Philip Schwarz
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
Leveraging benefits of the functional paradigm
Leveraging benefits of the functional paradigmLeveraging benefits of the functional paradigm
Leveraging benefits of the functional paradigmAfif Mohammed
 
Definitions of Functional Programming
Definitions of Functional ProgrammingDefinitions of Functional Programming
Definitions of Functional ProgrammingPhilip Schwarz
 

Tendances (14)

Of Lambdas and LINQ
Of Lambdas and LINQOf Lambdas and LINQ
Of Lambdas and LINQ
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Virtual function and abstract class
Virtual function and abstract classVirtual function and abstract class
Virtual function and abstract class
 
Python Built-in Functions and Use cases
Python Built-in Functions and Use casesPython Built-in Functions and Use cases
Python Built-in Functions and Use cases
 
XII Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-FunctionXII  Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-Function
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
 
ACM init()- Day 4
ACM init()- Day 4ACM init()- Day 4
ACM init()- Day 4
 
Compositionality and Category Theory - a montage of slides/transcript for sec...
Compositionality and Category Theory - a montage of slides/transcript for sec...Compositionality and Category Theory - a montage of slides/transcript for sec...
Compositionality and Category Theory - a montage of slides/transcript for sec...
 
Simplicitly
SimplicitlySimplicitly
Simplicitly
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Virtual Function
Virtual FunctionVirtual Function
Virtual Function
 
Leveraging benefits of the functional paradigm
Leveraging benefits of the functional paradigmLeveraging benefits of the functional paradigm
Leveraging benefits of the functional paradigm
 
Definitions of Functional Programming
Definitions of Functional ProgrammingDefinitions of Functional Programming
Definitions of Functional Programming
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 

Similaire à Conjfeatures

FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleChristophe Grand
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method OverloadingMichael Heron
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8Heartin Jacob
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scopingPatrick Sheridan
 
Intro To C++ - Class #20: Functions, Recursion
Intro To C++ - Class #20: Functions, RecursionIntro To C++ - Class #20: Functions, Recursion
Intro To C++ - Class #20: Functions, RecursionBlue Elephant Consulting
 
Clojure's take on concurrency
Clojure's take on concurrencyClojure's take on concurrency
Clojure's take on concurrencyyoavrubin
 
Extending Python with ctypes
Extending Python with ctypesExtending Python with ctypes
Extending Python with ctypesAnant Narayanan
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptxAtharvPotdar2
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersNLJUG
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleNoam Kfir
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphismkinan keshkeh
 
.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup
 
Iterable, iterator, generator by gaurav khurana
Iterable, iterator, generator by gaurav khuranaIterable, iterator, generator by gaurav khurana
Iterable, iterator, generator by gaurav khuranaGaurav Khurana
 
Intro to elixir and phoenix
Intro to elixir and phoenixIntro to elixir and phoenix
Intro to elixir and phoenixJared Smith
 

Similaire à Conjfeatures (20)

Functions
FunctionsFunctions
Functions
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit Hole
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scoping
 
Intro To C++ - Class #20: Functions, Recursion
Intro To C++ - Class #20: Functions, RecursionIntro To C++ - Class #20: Functions, Recursion
Intro To C++ - Class #20: Functions, Recursion
 
Clojure's take on concurrency
Clojure's take on concurrencyClojure's take on concurrency
Clojure's take on concurrency
 
Extending Python with ctypes
Extending Python with ctypesExtending Python with ctypes
Extending Python with ctypes
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx
 
Tofu and its environment
Tofu and its environmentTofu and its environment
Tofu and its environment
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen Borgers
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
 
.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves
 
Iterable, iterator, generator by gaurav khurana
Iterable, iterator, generator by gaurav khuranaIterable, iterator, generator by gaurav khurana
Iterable, iterator, generator by gaurav khurana
 
Variables in Pharo
Variables in PharoVariables in Pharo
Variables in Pharo
 
Intro to elixir and phoenix
Intro to elixir and phoenixIntro to elixir and phoenix
Intro to elixir and phoenix
 

Dernier

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Dernier (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Conjfeatures

  • 1. New Features in Clojure Rich Hickey
  • 2. Overview • Unified primitive semantics • Map key equality • Improved interaction between dynamic binding and thread pools • Explicitly dynamic vars • Primitive support in fns • This is all work-in-progress!
  • 3. Objective - Unify Semantics • Unify primitive and boxed integer semantics • Currently, boxed integer arithmetic promotes to bigint as needed • Primitive arithmetic throws on overflow • Means that you always have to be explicit about primitives • difficulty with representation choices • incidental boxing changes meaning
  • 4. Objective - Make Fast Numerics Simple • Would like to have literal numbers be used as primitives when possible • Ditto primitive method returns • Coercion and primitive ops currently for experts only • Easy to fail to optimize
  • 5. Unified Integer Semantics • The semantics of primitive longs, plus throw on overflow • This is the only semantic that works for both boxed and primitive • For bigint arithmetic, specify bigint operands • new literal bigint format: 42N • Polymorphic boxed numeric tower still in place • bigints now contagious, no more auto- reductions
  • 6. Numeric Features • Literal numbers are now treated implicitly as primitives • Locals known to be numbers are automatically coerced to long or double • More automatic conversions • int matches long, float matches double • Consistent canonic integer boxing • If fits in long, is Long
  • 7. Numeric Features • longs also match ints, and doubles match floats • long->int is checked • Can’t force boxed representation from primitive coercion: • was always a bug to presume otherwise • (class (int 42)) => Long • ditto boxed values coming from arrays of primitives, and primitive returns from interop
  • 8. Auto-promotion • No longer the default • Still available explicitly • ’ is now a constituent character (like #) • +', -', *', inc', dec' do auto-promotion • never return primitives • Unless you need to work with arbitrary- precision integers where BigInt contagion is insufficient, there is no reason to use them.
  • 9. Objective - Align Map Keys and Numeric = • Users frustrated when insert with one key representation, lookup fails with another • Use (type flexible) equivalence for map = • but narrow equiv, only same category numbers are = • so floats not = to integers • but == still available for that • new clojure.lang.BigInt class
  • 10. Map Key Equality • Hash maps and sets now use = for keys • this will make maps and sets unify 42 and 42N, since using = • Will still use stricter .equals when calling through java.util interfaces • Not there yet • this will require renaming Associative.containsKey, since semantics will now differ
  • 11. Objective - Make Binding Work with Threads • When work is sent to thread-pool threads, e.g. via agent sends or future calls, the work isn't done with the same binding set as the invocation (without manual effort) • Yet that is often the expectation/desire • Makes transparent parallelization difficult • Current tools for propagating bindings are expensive
  • 12. Binding Issues • Intended to be used within one thread • Don’t support a notion of task or unit of work crossing threads • Unsafe if used between threads • thus, must be copied • i.e., new bindings created for subtask thread
  • 13. Thread Issues • Threads don’t align with work tree • And when threads used for subtasks, not usually explicitly launched as children • thread pool threads (re-)used instead • Need better notion of subtasks not aligned with thread stack
  • 14. Shared Bindings • Allow subtasks in thread pool threads to share bindings with parent task • Make binding access safe from subtask threads • Add volatile semantics for binding values • Ensure vars only set! from binding thread • Sharing bindings is extremely fast • Just use same (immutable) binding map in subtask thread
  • 15. Binding Conveyance • Bindings are now automatically shared with threads used for future calls and agent sends • and anything built on them, e.g. pmap • This reroots the binding frame for thread pool thread prior to your work fn running • so bindings in work fn ‘win’ • Just works
  • 16. Binding and Scopes • Much of this work driven by needs of resource scopes • Natural fit for binding • But need same notion of task tree • and without conveyance, would have same thread problems/surprises as bindings • Scopes work can now proceed
  • 17. Objective - Pay for What You Use • All defs currently create fully dynamically rebindable vars • Incur cost for every access • Is it dynamically bound? • Is it unbound? • What’s the current value • Yet most vars (defns) have rarely-changing values, never dynamically bound
  • 18. Why Top Level Vars? • Traditional context-bound dynamic variables, like *out* et al • Dynamically bound fns can be used for error handling • Replace fns with fixed versions • Doesn’t require rebinding • Mutable globals
  • 19. Be Explicit about Dynamic Intent • Change default semantic from dynamically rebindable to not • Must declare vars dynamic using • ^:dynamic metadata • or .setDynamic on manually created Vars • Better for consumers • Enables significant optimizations
  • 20. Metadata Features • New ^:keyword metadata • turns into ^{:keyword true} • Metadata stacks - ^:dynamic ^:private foo • Merges rather than replaces • same as ^{:dynamic true :private true} foo
  • 21. Remove Overhead • Remove binding check from access to non- dynamics • Remove bound check from normal access • instead return Unbound object • has the var as field, prints in toString • implements IFn and throws on any invoke, with good message
  • 22. Presume Stability • Replace via defn to fix bugs case still remains • infrequent, but would like to avoid pain of static (i.e., re-eval of caller code) • Minimize overhead • cache var values in fn • global var rev, inc on any var alteration • check rev on fn entry and reload vars if changed • else use cached values
  • 23. Objective - Support Primitive Args/Returns • Clojure supports primitive arithmetic locally, and primitives in deftype/defrecord • But not in fn arguments or returns • Means you can’t break up your logic, or write helper functions, without introducing boxing
  • 24. Issues • fn is specified by an interface (IFn), taking and returning Objects • fns must still satisfy that interface • How will callers know about primitive params/return, and how to invoke? • Support ^long and ^double type hints on args/return
  • 25. IFn$LOD... • New set of single-method nested IFn interfaces • Corresponding to all combinations of Object/long/double, to arity 4 • Compiler will compile invokePrim methods in addition to IFn virtual invoke methods • When compiling direct invocation of prim fn, compiler will look at arglists metadata and make call to invokePrim method • var still contains IFn object for HOFs etc
  • 26. More Features • ^long and ^double hints supported on args • hint for return goes on arg vector • e.g. (defn foo ^long [x] ...) • so supports multi-arity with varied returns • Other reference type hints allowed as well • Just for hints, not enforced
  • 27. Future Fns • Primitive-taking fn interfaces open door to non-boxing HOFs • One more step to dynamically typed, yet internally primitive, map and reduce • When combined with collections of primitives • and chunked seqs
  • 28. Summary • New features enable much faster code • Unified semantics reduce complexity • all features are still available • auto-promotion is explicit • dynamic binding is explicit • Optimization more automatic, less work, less subtle • Pave the way for scopes and primitive HOFs

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n