SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
Demystifying (λ)Functional Programming with
Clojure
-Rohit Vaidya
Agenda
● Functional Programming
● Some Functional Jargon
● Understand Clojure
● Clojure Syntax
● Lein - Build tools for Clojure
● Meta Programming
Functional Programming
● Functional Programming takes a
mathematical view of the world
● Nothing but elaboration of Lambda
Calculus
λ- Calculus
● λ-Calculus is universal model of
Computation
● Can be used to simulate a taped turing
machine
● λ-Calculus treats functions anonymously
● Computable functions are fundamental to
math and CS.
● λ-Calculus provides semantics for
computation
λ- Calculus
squaresum( x , y)→ x
2
+y
2
(x , y) → x
2
+ y
2
(( x , y)→ x
2
+y
2
)(4,3)
→4
2
+3
2
→25
(x →( y → x
2
+y
2
)(5))(2)
( y →5
2
+y
2
)(2)
5
2
+2
2
29
Jargon
● Homoiconic Language - Program
structure is similar to its syntax
● Metaprogramming - Metaprogramming is
the art of writing of computer programs with
the ability to treat programs as their data
● Referential Transparency (Pure) -
Always returns the same result for a given
argument
Functional Programming-Clojure
● First class functions
● Immutable Data Structures
● Recursive looping
● Facilitates concurrency
Why Clojure?
● A Lisp – dynamic language
● Functional Programming
● Symbiotic with an established Platform
● Designed for Concurrency
● Embraces the JVM (Native to the JVM)
● Clojure is concise – Code as Data
– (+ 3 2) This is a function call
– '(+ 3 2) This is data
Why Clojure?
● You can tranlate data into function call at
runtime
● Performs better than JavaScript, Ruby and
Python
● Macros- Extending the Language
– e.g: HTML templating is bloated
– In java you mix HTML with Java or Java
with HTML
– What if your language knows generating
HTML?
Why Clojure?
– [:a {:href "http://github.com"} "GitHub"]
– This converts to
– <a href="http://github.com">GitHub</a>
– The above can be done using Hiccup
● Has a REPL
● Define functions on the fly
Clojure Syntax
● ()[]{} Everything within () gets evaluated
● Almost no syntax rules
● Lisp Syntax (data = code).Code as Data!!!
● Lets write a simple function
– Anonymous Function
– Named function
Atomic Data Types
● Nil means nothing. Same as Java null
● Booleans true false
● Doubles 1.234 BigDecimals 10.123M
● Ratios 22/7
● Strings “fred” Characters a b c
● Regex #”a*x”
Atomic Data
● Use clojure.core/class function to identify
type of data
Clojure Functions
● Create a Clojure Function
1.Bind Name add to the function
2.Anonymous function with arguments x y
1.fn creates a anonymous function
3.Function description
4.Function body
1
2
31
4
Clojure Function
● Define function with macro form defn
1
2
3
1. Create a function add with x, y
arguments
2. Function description
3. Function Body
Clojure Function Pure vs Impure
● Referential Transparency
1. Is pure. For certain x,y it will always return
same result
2. Is impure. Getting a hike is dependent on
side effect and not always deterministic
1 2
Special Forms
● Primitives build in clojure to perform core
operations
● If do let fn loop recur etc are special forms
● (if true 1 2)
– Returns 1
● (let [x 3] println x)
– Prints 3
– Scope restricted to let statment
Lists, Vectors, Sets and Maps
● Vectors
– Similar to Array
– 0 based collection
– Syntax
● [1 2 3]
● (def abc [1 2 3])
● (get abc 0)
Lists, Vectors, Sets and Maps
● Lists
– Similar to Vectors
– Cannot use get against lists
– Syntax
● '(1 2 3)
● (nth '(1 2 3) 0)
● Lists to used if you want to add elements to
the beginning
– (conj '(1 2 3) 4) returns 4 1 2 3
Lists, Vectors, Sets and Maps
● Maps
– Similars to dictionaries or hashes
– Two types in Clojure
● HashMaps
● SortedMaps
– Syntax:
● {:firstName “Rohit” :lastName “Vaidya”}
● (def hm {:a 1 :b 2})
● (get hm :a) returns 1
Lists, Vectors, Sets and Maps
● HashSet
– Sets are collection on unique values
– Syntax
● (hash-set 1 2 3 3 2 1)
– Create a hash set
● (contains? (hash-set 1 2 2 1 1) 1)
– Check presense of a element
– Returns true
Lists, Vectors, Sets and Maps
● HashSet
– Sets are collection on unique values
– Syntax
● (hash-set 1 2 3 3 2 1)
– Create Hash Set
● (contains? (hash-set 1 2 2 1 1) 1)
– Check presense of element
– Returns true
Programming to Abstractions
● Sequence Abstraction, abstracts
– List,
– Vector
– Set and Map
● Clojure defines map and reduce in terms of
sequence abstractions and not any specific
data structure
● y1 = f(x1), y2 = f(x2), . . . yn = f(x n).
Programming to Abstractions
● Visualizing mapping on a sequence abstraction
Programming to Abstractions
1. Define a increment function
2. Function description
3. Argument
4. Function Body
5. Map applied to a sequence(Vector). Map is a higher order function
1
2
3
4
5
Loops using Recursion
1. First function overload
with zero arugment with
arity 0
2. Second function overload
with 1 argument i.e arity 1
3. Recursive call to by
passing incremented
value of number
1
2
3
Loops with Recursion
1
2
• Clojure equivalent of 1 in 2
Metaprogramming – Alchemy
● Reader: Is a clojure Parser
– Converts text into clojure data structure
● Read String converts to list
Metaprogramming - Alchemy
1. Read a string and convert to list (data)
2. Read a String and evaluate it. Clojure expected operator.
3. Constructed prefix (reverse polish) with infix expression
4. Evaluated the constrcuted prefix expression
1
2
3
4
Metaprogramming - Alchemy
● Defmacro defines a
macro
● Lesser verbose,
metaprogramming
1. Define a macro
2. Argument for macro
3. Prefix to infix
4. Call to a macro
1
2
3
4
High Order Functions
● When a language takes a fn as arugment
or returns fn as result
● A higher order function is
– A function that takes function arguments
– A function that retuns a function
● Some well known higher order functions
– Map Reduce Remove
Filter Iterate
Lein – the build tool
● Lein commands
– lein new app clojure-noob
– lein run
– lein test
● Lein web app
– lein new luminus my-app
– cd my-app
– lein run
References
● https://clojurebridge.github.io/community-docs/
● http://www.slideshare.net/smartrevolution/how-a-
● http://www.braveclojure.com/
● http://xahlee.info/clojure/clojure_index.html
● https://www.gnu.org/software/emacs/
● https://mitpress.mit.edu/sicp/
● Clojure by Rich Hickey
● 4Clojure
SICP

Contenu connexe

Tendances

Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
Adelina Ahadova
 
Day 3 examples u6f13
Day 3 examples u6f13Day 3 examples u6f13
Day 3 examples u6f13
jchartiersjsd
 

Tendances (20)

C++ Returning Objects
C++ Returning ObjectsC++ Returning Objects
C++ Returning Objects
 
Scala for Java Developers
Scala for Java DevelopersScala for Java Developers
Scala for Java Developers
 
Nikit
NikitNikit
Nikit
 
Refinement Types for Haskell
Refinement Types for HaskellRefinement Types for Haskell
Refinement Types for Haskell
 
Comparing Haskell & Scala
Comparing Haskell & ScalaComparing Haskell & Scala
Comparing Haskell & Scala
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 
binary search
binary searchbinary search
binary search
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Fluent14
Fluent14Fluent14
Fluent14
 
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & SearchingHub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
 
Merge sort
Merge sortMerge sort
Merge sort
 
Big o notation
Big o notationBig o notation
Big o notation
 
Clojure - LISP on the JVM
Clojure - LISP on the JVM Clojure - LISP on the JVM
Clojure - LISP on the JVM
 
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury SechetDConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
 
Java & OOP Core Concept
Java & OOP Core ConceptJava & OOP Core Concept
Java & OOP Core Concept
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
Day 3 examples u6f13
Day 3 examples u6f13Day 3 examples u6f13
Day 3 examples u6f13
 

Similaire à Clojure

A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
Paul Lam
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
Miles Sabin
 
Design and Implementation of the Security Graph Language
Design and Implementation of the Security Graph LanguageDesign and Implementation of the Security Graph Language
Design and Implementation of the Security Graph Language
Asankhaya Sharma
 

Similaire à Clojure (20)

Clojure intro
Clojure introClojure intro
Clojure intro
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
Scala qq
Scala qqScala qq
Scala qq
 
Java 8
Java 8Java 8
Java 8
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
Functional Programming with Clojure
Functional Programming with ClojureFunctional Programming with Clojure
Functional Programming with Clojure
 
Clojure presentation
Clojure presentationClojure presentation
Clojure presentation
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
 
06. haskell type builder
06. haskell type builder06. haskell type builder
06. haskell type builder
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
 
Neo4j: Graph-like power
Neo4j: Graph-like powerNeo4j: Graph-like power
Neo4j: Graph-like power
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
An Intoduction to R
An Intoduction to RAn Intoduction to R
An Intoduction to R
 
Design and Implementation of the Security Graph Language
Design and Implementation of the Security Graph LanguageDesign and Implementation of the Security Graph Language
Design and Implementation of the Security Graph Language
 
Elixir basics
Elixir basicsElixir basics
Elixir basics
 
Scheme 核心概念(一)
Scheme 核心概念(一)Scheme 核心概念(一)
Scheme 核心概念(一)
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Clojure

  • 1. Demystifying (λ)Functional Programming with Clojure -Rohit Vaidya
  • 2. Agenda ● Functional Programming ● Some Functional Jargon ● Understand Clojure ● Clojure Syntax ● Lein - Build tools for Clojure ● Meta Programming
  • 3. Functional Programming ● Functional Programming takes a mathematical view of the world ● Nothing but elaboration of Lambda Calculus
  • 4. λ- Calculus ● λ-Calculus is universal model of Computation ● Can be used to simulate a taped turing machine ● λ-Calculus treats functions anonymously ● Computable functions are fundamental to math and CS. ● λ-Calculus provides semantics for computation
  • 5. λ- Calculus squaresum( x , y)→ x 2 +y 2 (x , y) → x 2 + y 2 (( x , y)→ x 2 +y 2 )(4,3) →4 2 +3 2 →25 (x →( y → x 2 +y 2 )(5))(2) ( y →5 2 +y 2 )(2) 5 2 +2 2 29
  • 6. Jargon ● Homoiconic Language - Program structure is similar to its syntax ● Metaprogramming - Metaprogramming is the art of writing of computer programs with the ability to treat programs as their data ● Referential Transparency (Pure) - Always returns the same result for a given argument
  • 7. Functional Programming-Clojure ● First class functions ● Immutable Data Structures ● Recursive looping ● Facilitates concurrency
  • 8. Why Clojure? ● A Lisp – dynamic language ● Functional Programming ● Symbiotic with an established Platform ● Designed for Concurrency ● Embraces the JVM (Native to the JVM) ● Clojure is concise – Code as Data – (+ 3 2) This is a function call – '(+ 3 2) This is data
  • 9. Why Clojure? ● You can tranlate data into function call at runtime ● Performs better than JavaScript, Ruby and Python ● Macros- Extending the Language – e.g: HTML templating is bloated – In java you mix HTML with Java or Java with HTML – What if your language knows generating HTML?
  • 10. Why Clojure? – [:a {:href "http://github.com"} "GitHub"] – This converts to – <a href="http://github.com">GitHub</a> – The above can be done using Hiccup ● Has a REPL ● Define functions on the fly
  • 11. Clojure Syntax ● ()[]{} Everything within () gets evaluated ● Almost no syntax rules ● Lisp Syntax (data = code).Code as Data!!! ● Lets write a simple function – Anonymous Function – Named function
  • 12. Atomic Data Types ● Nil means nothing. Same as Java null ● Booleans true false ● Doubles 1.234 BigDecimals 10.123M ● Ratios 22/7 ● Strings “fred” Characters a b c ● Regex #”a*x”
  • 13. Atomic Data ● Use clojure.core/class function to identify type of data
  • 14. Clojure Functions ● Create a Clojure Function 1.Bind Name add to the function 2.Anonymous function with arguments x y 1.fn creates a anonymous function 3.Function description 4.Function body 1 2 31 4
  • 15. Clojure Function ● Define function with macro form defn 1 2 3 1. Create a function add with x, y arguments 2. Function description 3. Function Body
  • 16. Clojure Function Pure vs Impure ● Referential Transparency 1. Is pure. For certain x,y it will always return same result 2. Is impure. Getting a hike is dependent on side effect and not always deterministic 1 2
  • 17. Special Forms ● Primitives build in clojure to perform core operations ● If do let fn loop recur etc are special forms ● (if true 1 2) – Returns 1 ● (let [x 3] println x) – Prints 3 – Scope restricted to let statment
  • 18. Lists, Vectors, Sets and Maps ● Vectors – Similar to Array – 0 based collection – Syntax ● [1 2 3] ● (def abc [1 2 3]) ● (get abc 0)
  • 19. Lists, Vectors, Sets and Maps ● Lists – Similar to Vectors – Cannot use get against lists – Syntax ● '(1 2 3) ● (nth '(1 2 3) 0) ● Lists to used if you want to add elements to the beginning – (conj '(1 2 3) 4) returns 4 1 2 3
  • 20. Lists, Vectors, Sets and Maps ● Maps – Similars to dictionaries or hashes – Two types in Clojure ● HashMaps ● SortedMaps – Syntax: ● {:firstName “Rohit” :lastName “Vaidya”} ● (def hm {:a 1 :b 2}) ● (get hm :a) returns 1
  • 21. Lists, Vectors, Sets and Maps ● HashSet – Sets are collection on unique values – Syntax ● (hash-set 1 2 3 3 2 1) – Create a hash set ● (contains? (hash-set 1 2 2 1 1) 1) – Check presense of a element – Returns true
  • 22. Lists, Vectors, Sets and Maps ● HashSet – Sets are collection on unique values – Syntax ● (hash-set 1 2 3 3 2 1) – Create Hash Set ● (contains? (hash-set 1 2 2 1 1) 1) – Check presense of element – Returns true
  • 23. Programming to Abstractions ● Sequence Abstraction, abstracts – List, – Vector – Set and Map ● Clojure defines map and reduce in terms of sequence abstractions and not any specific data structure ● y1 = f(x1), y2 = f(x2), . . . yn = f(x n).
  • 24. Programming to Abstractions ● Visualizing mapping on a sequence abstraction
  • 25. Programming to Abstractions 1. Define a increment function 2. Function description 3. Argument 4. Function Body 5. Map applied to a sequence(Vector). Map is a higher order function 1 2 3 4 5
  • 26. Loops using Recursion 1. First function overload with zero arugment with arity 0 2. Second function overload with 1 argument i.e arity 1 3. Recursive call to by passing incremented value of number 1 2 3
  • 27. Loops with Recursion 1 2 • Clojure equivalent of 1 in 2
  • 28. Metaprogramming – Alchemy ● Reader: Is a clojure Parser – Converts text into clojure data structure ● Read String converts to list
  • 29. Metaprogramming - Alchemy 1. Read a string and convert to list (data) 2. Read a String and evaluate it. Clojure expected operator. 3. Constructed prefix (reverse polish) with infix expression 4. Evaluated the constrcuted prefix expression 1 2 3 4
  • 30. Metaprogramming - Alchemy ● Defmacro defines a macro ● Lesser verbose, metaprogramming 1. Define a macro 2. Argument for macro 3. Prefix to infix 4. Call to a macro 1 2 3 4
  • 31. High Order Functions ● When a language takes a fn as arugment or returns fn as result ● A higher order function is – A function that takes function arguments – A function that retuns a function ● Some well known higher order functions – Map Reduce Remove Filter Iterate
  • 32. Lein – the build tool ● Lein commands – lein new app clojure-noob – lein run – lein test ● Lein web app – lein new luminus my-app – cd my-app – lein run
  • 33. References ● https://clojurebridge.github.io/community-docs/ ● http://www.slideshare.net/smartrevolution/how-a- ● http://www.braveclojure.com/ ● http://xahlee.info/clojure/clojure_index.html ● https://www.gnu.org/software/emacs/ ● https://mitpress.mit.edu/sicp/ ● Clojure by Rich Hickey ● 4Clojure
  • 34. SICP

Notes de l'éditeur

  1. Programs are functions that take certain values and produce certain values
  2. Lambda calculus is formal system in mathematical logic for expressing computation using functional abstraction and application using variable substituion
  3. Pair of x,y is mapped to x^2 + y^2
  4. Ghost of John McCarthy
  5. Programs are functions that take certain values and produce certain values
  6. Create a anonymous function Create a name bound function defn macro (defn hike [] (if (&amp;gt; (rand) 0.5) “You got hike” “Better luck next year”)) (-&amp;gt; 2 Inc Inc) ((fn [x y] (+ (* x x)(* y y)) 2 2)
  7. Create a record and get a value from it
  8. (defn increment [x] (inc x)) (map increment [ 0 1 2 3 ]) 1 2 3 4 (defn prefix [personalPronoun] (str PersonalPronoun “ Brave”)) (map prefix [“I” “you” “she” “he”)