SlideShare une entreprise Scribd logo
1  sur  34
Lisp Macros
                   in 20 minutes
                           (featuring ‘clojure)

                                               phillip calçado
                                            http://fragmental.tw
                                          http://thoughtworks.com


--:--   *LISP Macros in 20 minutes*   http://fragmental.tw (Presentation)--------------------------------------------------------
Clojure
Clojure


•homoiconic
•fairly functional
•runtime polymorphism
•jvm language
•software transactional memory
•agent-based asynchronous concurrency
Clojure


•homoiconic
•fairly functional
•runtime polymorphism
•jvm language
•software transactional memory
•agent-based asynchronous concurrency
Clojure


•homoiconic
•fairly functional
•runtime polymorphism
•jvm language
    Code is Data
•software transactional memory
•agent-based asynchronous concurrency

    Data is Code
Example:
LINQ Envy
C#


    string[] names = { quot;Burkequot;, quot;Connorquot;, quot;Frankquot;,
                       quot;Everettquot;, quot;Albertquot;, quot;Georgequot;,
                       quot;Harrisquot;, quot;Davidquot; };

    IEnumerable<string> query = from n in names
                               where n.Length == 5
                               orderby n
                               select n.ToUpper();

    foreach (string item in query)
      Console.WriteLine(item);
}
Java - Quaere


String[] names={quot;Burkequot;, quot;Connorquot;, quot;Frankquot;,
                       quot;Everettquot;, quot;Albertquot;, quot;Georgequot;,
                       quot;Harrisquot;, quot;Davidquot;};
Iterable<String> query=
        from(quot;nquot;).in(names).
        where(eq(quot;n.length()quot;,5).
        select(quot;n.toUpperCase()quot;);

for (String n: query) {
    System.out.println(n);
}
Ruby - Quick Hack


names = [quot;Burkequot;, quot;Connorquot;, quot;Frankquot;,
         quot;Everettquot;, quot;Albertquot;, quot;Georgequot;,
         quot;Harrisquot;, quot;Davidquot;]

query = from :n => names do
  where n.length => 5
  orderby n
  select n.upcase
end

query.each{|e| puts e   }
Clojure


(def names '(quot;Burkequot;, quot;Connorquot;, quot;Frankquot;,
                       quot;Everettquot;, quot;Albertquot;,
                       quot;Georgequot;, quot;Harrisquot;,
                       quot;Davidquot;))

(def query
      (from n in names
      where (= (. n length) 5)
      orderby n
      select (. n toUpperCase)))

(doseq [n query] (println n))
Ruby Hack - Implementation
class Parameter                                            def from(binding, &spec)
  def method_missing(method, *args)                         var = binding.keys.first
    method                                                  list = binding.values.last
  end                                                       query = Query.new var
end                                                         query.instance_eval &spec
                                                            list.select do |a|
class Query                                                   a.send(query.condition[:method]) ==
  attr_reader :condition, :criteria, :action              query.condition[:value]
                                                            end.sort do |a,b|
  def initialize(var)                                         if(query.criteria)
    singleton_class.send(:define_method, var)                   a.send(query.criteria) <=> b.send(query.criteria)
{ Parameter.new }                                             else
  end                                                           a <=> b
                                                              end
  def singleton_class; class << self; self; end; end        end.map do |a|
                                                              a.send(query.action)
  def where(cond)                                           end
    @condition = {:method => cond.keys.first, :value =>   end
cond.values.last}
  end

  def orderby(criteria)
    @criteria = criteria unless criteria.kind_of?
Parameter
  end

  def select(action)
    @action = action
  end
end
      a <=> b
    end
  end.map do |a|
    a.send(query.action)
  end
end
Clojure - Implementation




(defmacro from [var _ coll _ condition _ ordering _ desired-map]
  `(map (fn [~var] ~desired-map) (sort-by (fn[~var] ~ordering)
	      (filter (fn[~var] ~condition) ~coll))))
Code is Data
                     Data is Code
 “         InfoQ: [...] many modern programming languages like Ruby are claiming big
           influences from Lisp Have you seen those languages or do you have any ideas
           about the current state of programming languages?

           McCarthy: [...] I don't know enough for example about Ruby to know in what way
           it's related to Lisp. Does it use, for example, list structures as data?

           InfoQ: No.

           McCarthy: So if you want to compute with sums and products, you have to parse
           every time?

           InfoQ: Yes.

           McCarthy: So, in that respect Ruby still isn't up to where Lisp was in 1960.


Adapted From: http://www.infoq.com/interviews/mccarthy-elephant-2000*
Everything is
  a (List)
(1 2 3 4 5)


   (+ 1 2)


(+ (- 3 2) 10)
List


{
(1 2 3 4 5)


  Number
List


           {
       (+ 1 2)


Function     Number
List

     {
     (+ (- 3 2) 10)

       {   List
Function          Number
{
           (defn- run-variant[variant]
             (let [result
               (wrap-and-run


List
                 (:impl variant) (:args variant))]
                   (struct-map variant-result
                     :args (:args variant)
                     :result (first result)
                     :exception (second result))))
Code is Data
Data is Code
Example:
Implementing
     If
(defn they-are-the-same []
  (println quot;They are the same!quot;))

(defn they-are-different []
  (println quot;They are different!quot;))

(my-if (= 2 2)
       (they-are-the-same)
       (they-are-different))
First Try: Function



(defn my-if [condition succ fail]
  (cond
   condition succ
   :else fail))



user>
;;;; (my-if (= 2 2)         (they-are-the-
same)         (they-are ...
They are the same!
They are different!
Second Try: Macro



(defmacro my-if [condition succ fail]
  (cond
   condition succ
   :else fail))



user>
;;;; (my-if (= 2 2)         (they-are-the-
same)         (they-are ...
They are the same!
Why? Dump Function Arguments



(defn my-if [condition succ fail]
  (println quot;Parameters are: quot; condition
succ fail))



user>
user>
;;;; (my-if (= 2 2)         (they-are-the-
same)         (they-are ...
They are the same!
They are different!
Parameters are: true nil nil
Why? Dump Macro Arguments



(defmacro my-if [condition succ fail]
  (println quot;Parameters are: quot; condition
succ fail))



user>
user>
;;;; (My-if (= 2 2)         (they-are-the-
same)         (they-are ...
Parameters are: (= 2 2) (they-are-the-
same) (they-are-different)
Macro Expansion



(println (macroexpand-1 '(my-if (= 2 2)
		         (they-are-the-same)
		         (they-are-different)))




user>
user>
(they-are-the-same)
(my-if (= 2 2)
       (they-are-the-same)
       (they-are-different))




(defmacro my-if [condition succ fail]
  (cond
   condition succ
   :else fail))




(they-are-the-same)
Revisiting
  LINQ
Clojure - Implementation




(defmacro from [var _ coll _ condition _ ordering _ desired-map]
  `(map (fn [~var] ~desired-map) (sort-by (fn[~var] ~ordering)
	      (filter (fn[~var] ~condition) ~coll))))
(def query
      (from n in names
      where (= (. n length) 5)
      orderby n
      select (. n toUpperCase)))



(defmacro from [var _ coll _ condition _ ordering _
desired-map]
  `(map (fn [~var] ~desired-map) (sort-by (fn[~var]
~ordering)
	      (filter (fn[~var] ~condition) ~coll))))




(map (fn [n] (. n toUpperCase)) (sort-by (fn [n] n)
(filter (fn [n] (= (. n length) 5)) names)))
More?
http://www.pragprog.com/titles/shcloj/
programming-clojure

http://www.lisperati.com/casting.html

http://groups.google.com/group/clojure

http://www.gigamonkeys.com/book/

http://mitpress.mit.edu/sicp/

http://github.com/pcalcado/fato/tree/master

Contenu connexe

Tendances

Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Codemotion
 
Process Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux KernelProcess Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux KernelHaifeng Li
 
Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Philip Schwarz
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsBrendan Gregg
 
Functional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorldFunctional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorldJorge Vásquez
 
Functional programming
Functional programmingFunctional programming
Functional programmingijcd
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptNascenia IT
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and EffectsMartin Odersky
 
Quill vs Slick Smackdown
Quill vs Slick SmackdownQuill vs Slick Smackdown
Quill vs Slick SmackdownAlexander Ioffe
 
Docker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutesDocker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutesLuciano Fiandesio
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to AdvancedTalentica Software
 
The SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and ComputationThe SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and ComputationJean-Jacques Dubray
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Philip Schwarz
 
High performance in react native
High performance in react nativeHigh performance in react native
High performance in react nativeViet Tran
 
Systemd 간략하게 정리하기
Systemd 간략하게 정리하기Systemd 간략하게 정리하기
Systemd 간략하게 정리하기Seungha Son
 
The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421Linaro
 
Golang 101
Golang 101Golang 101
Golang 101宇 傅
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Sandro Mancuso
 

Tendances (20)

Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
 
Process Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux KernelProcess Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux Kernel
 
Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Sequence and Traverse - Part 1
Sequence and Traverse - Part 1
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old Secrets
 
Functional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorldFunctional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorld
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging modulePython Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging module
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and Effects
 
Quill vs Slick Smackdown
Quill vs Slick SmackdownQuill vs Slick Smackdown
Quill vs Slick Smackdown
 
Docker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutesDocker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutes
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
The SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and ComputationThe SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and Computation
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2
 
High performance in react native
High performance in react nativeHigh performance in react native
High performance in react native
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Systemd 간략하게 정리하기
Systemd 간략하게 정리하기Systemd 간략하게 정리하기
Systemd 간략하게 정리하기
 
The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421
 
Golang 101
Golang 101Golang 101
Golang 101
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014
 

Similaire à Lisp Macros in 20 Minutes (Featuring Clojure)

Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMsunng87
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議dico_leque
 
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
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)Jacek Laskowski
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Raffi Krikorian
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and MonoidsHugo Gävert
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - StockholmJan Kronquist
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lispkyleburton
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Introzhang tao
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 
Dynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web siteDynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web siteSriram Natarajan
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeJosh Mock
 

Similaire à Lisp Macros in 20 Minutes (Featuring Clojure) (20)

Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
 
Groovy
GroovyGroovy
Groovy
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
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
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Dynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web siteDynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web site
 
Beyond java8
Beyond java8Beyond java8
Beyond java8
 
Perl basics for pentesters part 2
Perl basics for pentesters part 2Perl basics for pentesters part 2
Perl basics for pentesters part 2
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 

Plus de Phil Calçado

the afterparty: refactoring after 100x hypergrowth
the afterparty: refactoring after 100x hypergrowththe afterparty: refactoring after 100x hypergrowth
the afterparty: refactoring after 100x hypergrowthPhil Calçado
 
don't try this at home: self-improvement as a senior leader
don't try this at home: self-improvement as a senior leaderdon't try this at home: self-improvement as a senior leader
don't try this at home: self-improvement as a senior leaderPhil Calçado
 
The Economics of Microservices (redux)
The Economics of Microservices (redux)The Economics of Microservices (redux)
The Economics of Microservices (redux)Phil Calçado
 
From microservices to serverless - Chicago CTO Summit 2019
From microservices to serverless - Chicago CTO Summit 2019From microservices to serverless - Chicago CTO Summit 2019
From microservices to serverless - Chicago CTO Summit 2019Phil Calçado
 
The Not-So-Straightforward Road From Microservices to Serverless
The Not-So-Straightforward Road From Microservices to ServerlessThe Not-So-Straightforward Road From Microservices to Serverless
The Not-So-Straightforward Road From Microservices to ServerlessPhil Calçado
 
Ten Years of Failing Microservices
Ten Years of Failing MicroservicesTen Years of Failing Microservices
Ten Years of Failing MicroservicesPhil Calçado
 
The Next Generation of Microservices
The Next Generation of MicroservicesThe Next Generation of Microservices
The Next Generation of MicroservicesPhil Calçado
 
The Next Generation of Microservices — YOW 2017 Brisbane
The Next Generation of Microservices — YOW 2017 BrisbaneThe Next Generation of Microservices — YOW 2017 Brisbane
The Next Generation of Microservices — YOW 2017 BrisbanePhil Calçado
 
The Economics of Microservices (2017 CraftConf)
The Economics of Microservices  (2017 CraftConf)The Economics of Microservices  (2017 CraftConf)
The Economics of Microservices (2017 CraftConf)Phil Calçado
 
Microservices vs. The First Law of Distributed Objects - GOTO Nights Chicago ...
Microservices vs. The First Law of Distributed Objects - GOTO Nights Chicago ...Microservices vs. The First Law of Distributed Objects - GOTO Nights Chicago ...
Microservices vs. The First Law of Distributed Objects - GOTO Nights Chicago ...Phil Calçado
 
Finagle @ SoundCloud
Finagle @ SoundCloudFinagle @ SoundCloud
Finagle @ SoundCloudPhil Calçado
 
A Brief Talk On High-Performing Organisations
A Brief Talk On High-Performing OrganisationsA Brief Talk On High-Performing Organisations
A Brief Talk On High-Performing OrganisationsPhil Calçado
 
Three Years of Microservices at SoundCloud - Distributed Matters Berlin 2015
Three Years of Microservices at SoundCloud - Distributed Matters Berlin 2015Three Years of Microservices at SoundCloud - Distributed Matters Berlin 2015
Three Years of Microservices at SoundCloud - Distributed Matters Berlin 2015Phil Calçado
 
Rhein-Main Scala Enthusiasts — Your microservice as a Function
Rhein-Main Scala Enthusiasts — Your microservice as a FunctionRhein-Main Scala Enthusiasts — Your microservice as a Function
Rhein-Main Scala Enthusiasts — Your microservice as a FunctionPhil Calçado
 
ScalaItaly 2015 - Your Microservice as a Function
ScalaItaly 2015 - Your Microservice as a FunctionScalaItaly 2015 - Your Microservice as a Function
ScalaItaly 2015 - Your Microservice as a FunctionPhil Calçado
 
Finagle-Based Microservices at SoundCloud
Finagle-Based Microservices at SoundCloudFinagle-Based Microservices at SoundCloud
Finagle-Based Microservices at SoundCloudPhil Calçado
 
An example of Future composition in a real app
An example of Future composition in a real appAn example of Future composition in a real app
An example of Future composition in a real appPhil Calçado
 
APIs: The Problems with Eating your Own Dog Food
APIs: The Problems with Eating your Own Dog FoodAPIs: The Problems with Eating your Own Dog Food
APIs: The Problems with Eating your Own Dog FoodPhil Calçado
 
Evolutionary Architecture at Work
Evolutionary  Architecture at WorkEvolutionary  Architecture at Work
Evolutionary Architecture at WorkPhil Calçado
 
Structuring apps in Scala
Structuring apps in ScalaStructuring apps in Scala
Structuring apps in ScalaPhil Calçado
 

Plus de Phil Calçado (20)

the afterparty: refactoring after 100x hypergrowth
the afterparty: refactoring after 100x hypergrowththe afterparty: refactoring after 100x hypergrowth
the afterparty: refactoring after 100x hypergrowth
 
don't try this at home: self-improvement as a senior leader
don't try this at home: self-improvement as a senior leaderdon't try this at home: self-improvement as a senior leader
don't try this at home: self-improvement as a senior leader
 
The Economics of Microservices (redux)
The Economics of Microservices (redux)The Economics of Microservices (redux)
The Economics of Microservices (redux)
 
From microservices to serverless - Chicago CTO Summit 2019
From microservices to serverless - Chicago CTO Summit 2019From microservices to serverless - Chicago CTO Summit 2019
From microservices to serverless - Chicago CTO Summit 2019
 
The Not-So-Straightforward Road From Microservices to Serverless
The Not-So-Straightforward Road From Microservices to ServerlessThe Not-So-Straightforward Road From Microservices to Serverless
The Not-So-Straightforward Road From Microservices to Serverless
 
Ten Years of Failing Microservices
Ten Years of Failing MicroservicesTen Years of Failing Microservices
Ten Years of Failing Microservices
 
The Next Generation of Microservices
The Next Generation of MicroservicesThe Next Generation of Microservices
The Next Generation of Microservices
 
The Next Generation of Microservices — YOW 2017 Brisbane
The Next Generation of Microservices — YOW 2017 BrisbaneThe Next Generation of Microservices — YOW 2017 Brisbane
The Next Generation of Microservices — YOW 2017 Brisbane
 
The Economics of Microservices (2017 CraftConf)
The Economics of Microservices  (2017 CraftConf)The Economics of Microservices  (2017 CraftConf)
The Economics of Microservices (2017 CraftConf)
 
Microservices vs. The First Law of Distributed Objects - GOTO Nights Chicago ...
Microservices vs. The First Law of Distributed Objects - GOTO Nights Chicago ...Microservices vs. The First Law of Distributed Objects - GOTO Nights Chicago ...
Microservices vs. The First Law of Distributed Objects - GOTO Nights Chicago ...
 
Finagle @ SoundCloud
Finagle @ SoundCloudFinagle @ SoundCloud
Finagle @ SoundCloud
 
A Brief Talk On High-Performing Organisations
A Brief Talk On High-Performing OrganisationsA Brief Talk On High-Performing Organisations
A Brief Talk On High-Performing Organisations
 
Three Years of Microservices at SoundCloud - Distributed Matters Berlin 2015
Three Years of Microservices at SoundCloud - Distributed Matters Berlin 2015Three Years of Microservices at SoundCloud - Distributed Matters Berlin 2015
Three Years of Microservices at SoundCloud - Distributed Matters Berlin 2015
 
Rhein-Main Scala Enthusiasts — Your microservice as a Function
Rhein-Main Scala Enthusiasts — Your microservice as a FunctionRhein-Main Scala Enthusiasts — Your microservice as a Function
Rhein-Main Scala Enthusiasts — Your microservice as a Function
 
ScalaItaly 2015 - Your Microservice as a Function
ScalaItaly 2015 - Your Microservice as a FunctionScalaItaly 2015 - Your Microservice as a Function
ScalaItaly 2015 - Your Microservice as a Function
 
Finagle-Based Microservices at SoundCloud
Finagle-Based Microservices at SoundCloudFinagle-Based Microservices at SoundCloud
Finagle-Based Microservices at SoundCloud
 
An example of Future composition in a real app
An example of Future composition in a real appAn example of Future composition in a real app
An example of Future composition in a real app
 
APIs: The Problems with Eating your Own Dog Food
APIs: The Problems with Eating your Own Dog FoodAPIs: The Problems with Eating your Own Dog Food
APIs: The Problems with Eating your Own Dog Food
 
Evolutionary Architecture at Work
Evolutionary  Architecture at WorkEvolutionary  Architecture at Work
Evolutionary Architecture at Work
 
Structuring apps in Scala
Structuring apps in ScalaStructuring apps in Scala
Structuring apps in Scala
 

Dernier

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
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
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
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
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

Lisp Macros in 20 Minutes (Featuring Clojure)

  • 1. Lisp Macros in 20 minutes (featuring ‘clojure) phillip calçado http://fragmental.tw http://thoughtworks.com --:-- *LISP Macros in 20 minutes* http://fragmental.tw (Presentation)--------------------------------------------------------
  • 3. Clojure •homoiconic •fairly functional •runtime polymorphism •jvm language •software transactional memory •agent-based asynchronous concurrency
  • 4. Clojure •homoiconic •fairly functional •runtime polymorphism •jvm language •software transactional memory •agent-based asynchronous concurrency
  • 5. Clojure •homoiconic •fairly functional •runtime polymorphism •jvm language Code is Data •software transactional memory •agent-based asynchronous concurrency Data is Code
  • 7. C# string[] names = { quot;Burkequot;, quot;Connorquot;, quot;Frankquot;, quot;Everettquot;, quot;Albertquot;, quot;Georgequot;, quot;Harrisquot;, quot;Davidquot; }; IEnumerable<string> query = from n in names where n.Length == 5 orderby n select n.ToUpper(); foreach (string item in query) Console.WriteLine(item); }
  • 8. Java - Quaere String[] names={quot;Burkequot;, quot;Connorquot;, quot;Frankquot;, quot;Everettquot;, quot;Albertquot;, quot;Georgequot;, quot;Harrisquot;, quot;Davidquot;}; Iterable<String> query= from(quot;nquot;).in(names). where(eq(quot;n.length()quot;,5). select(quot;n.toUpperCase()quot;); for (String n: query) { System.out.println(n); }
  • 9. Ruby - Quick Hack names = [quot;Burkequot;, quot;Connorquot;, quot;Frankquot;, quot;Everettquot;, quot;Albertquot;, quot;Georgequot;, quot;Harrisquot;, quot;Davidquot;] query = from :n => names do where n.length => 5 orderby n select n.upcase end query.each{|e| puts e }
  • 10. Clojure (def names '(quot;Burkequot;, quot;Connorquot;, quot;Frankquot;, quot;Everettquot;, quot;Albertquot;, quot;Georgequot;, quot;Harrisquot;, quot;Davidquot;)) (def query (from n in names where (= (. n length) 5) orderby n select (. n toUpperCase))) (doseq [n query] (println n))
  • 11. Ruby Hack - Implementation class Parameter def from(binding, &spec) def method_missing(method, *args) var = binding.keys.first method list = binding.values.last end query = Query.new var end query.instance_eval &spec list.select do |a| class Query a.send(query.condition[:method]) == attr_reader :condition, :criteria, :action query.condition[:value] end.sort do |a,b| def initialize(var) if(query.criteria) singleton_class.send(:define_method, var) a.send(query.criteria) <=> b.send(query.criteria) { Parameter.new } else end a <=> b end def singleton_class; class << self; self; end; end end.map do |a| a.send(query.action) def where(cond) end @condition = {:method => cond.keys.first, :value => end cond.values.last} end def orderby(criteria) @criteria = criteria unless criteria.kind_of? Parameter end def select(action) @action = action end end a <=> b end end.map do |a| a.send(query.action) end end
  • 12. Clojure - Implementation (defmacro from [var _ coll _ condition _ ordering _ desired-map] `(map (fn [~var] ~desired-map) (sort-by (fn[~var] ~ordering) (filter (fn[~var] ~condition) ~coll))))
  • 13. Code is Data Data is Code “ InfoQ: [...] many modern programming languages like Ruby are claiming big influences from Lisp Have you seen those languages or do you have any ideas about the current state of programming languages? McCarthy: [...] I don't know enough for example about Ruby to know in what way it's related to Lisp. Does it use, for example, list structures as data? InfoQ: No. McCarthy: So if you want to compute with sums and products, you have to parse every time? InfoQ: Yes. McCarthy: So, in that respect Ruby still isn't up to where Lisp was in 1960. Adapted From: http://www.infoq.com/interviews/mccarthy-elephant-2000*
  • 14.
  • 15. Everything is a (List)
  • 16. (1 2 3 4 5) (+ 1 2) (+ (- 3 2) 10)
  • 17. List { (1 2 3 4 5) Number
  • 18. List { (+ 1 2) Function Number
  • 19. List { (+ (- 3 2) 10) { List Function Number
  • 20. { (defn- run-variant[variant] (let [result (wrap-and-run List (:impl variant) (:args variant))] (struct-map variant-result :args (:args variant) :result (first result) :exception (second result))))
  • 21.
  • 22. Code is Data Data is Code
  • 24. (defn they-are-the-same [] (println quot;They are the same!quot;)) (defn they-are-different [] (println quot;They are different!quot;)) (my-if (= 2 2) (they-are-the-same) (they-are-different))
  • 25. First Try: Function (defn my-if [condition succ fail] (cond condition succ :else fail)) user> ;;;; (my-if (= 2 2) (they-are-the- same) (they-are ... They are the same! They are different!
  • 26. Second Try: Macro (defmacro my-if [condition succ fail] (cond condition succ :else fail)) user> ;;;; (my-if (= 2 2) (they-are-the- same) (they-are ... They are the same!
  • 27. Why? Dump Function Arguments (defn my-if [condition succ fail] (println quot;Parameters are: quot; condition succ fail)) user> user> ;;;; (my-if (= 2 2) (they-are-the- same) (they-are ... They are the same! They are different! Parameters are: true nil nil
  • 28. Why? Dump Macro Arguments (defmacro my-if [condition succ fail] (println quot;Parameters are: quot; condition succ fail)) user> user> ;;;; (My-if (= 2 2) (they-are-the- same) (they-are ... Parameters are: (= 2 2) (they-are-the- same) (they-are-different)
  • 29. Macro Expansion (println (macroexpand-1 '(my-if (= 2 2) (they-are-the-same) (they-are-different))) user> user> (they-are-the-same)
  • 30. (my-if (= 2 2) (they-are-the-same) (they-are-different)) (defmacro my-if [condition succ fail] (cond condition succ :else fail)) (they-are-the-same)
  • 32. Clojure - Implementation (defmacro from [var _ coll _ condition _ ordering _ desired-map] `(map (fn [~var] ~desired-map) (sort-by (fn[~var] ~ordering) (filter (fn[~var] ~condition) ~coll))))
  • 33. (def query (from n in names where (= (. n length) 5) orderby n select (. n toUpperCase))) (defmacro from [var _ coll _ condition _ ordering _ desired-map] `(map (fn [~var] ~desired-map) (sort-by (fn[~var] ~ordering) (filter (fn[~var] ~condition) ~coll)))) (map (fn [n] (. n toUpperCase)) (sort-by (fn [n] n) (filter (fn [n] (= (. n length) 5)) names)))

Notes de l'éditeur