SlideShare uma empresa Scribd logo
1 de 35
Baixar para ler offline
ClojureScriptClojureScript
The Good PartsThe Good Parts
カマイルカ /laʒenɔʁɛ̃k/カマイルカ /laʒenɔʁɛ̃k/
lagénorhynquelagénorhynque
(defprofile lagénorhynque
:name "Kent OHASHI"
:languages [Clojure Haskell Python Scala
English français Deutsch русский]
:interests [programming language-learning mathematics]
:contributing [github.com/japan-clojurians/clojure-site-ja])
Lisp × JavaScriptLisp × JavaScript
What is ClojureScript?What is ClojureScript?
(CLJS)(CLJS)
compiler for Clojure that targets JavaScript
cf. (JVM/Java), (CLR/C#)
simple and powerful functional Lisp
ClojureScriptClojureScript
Clojure ClojureCLR
Use CasesUse Cases
SPA: / , , , etc.
React Native:
Electron
Node.js
AWS Lambda
etc.
Reagent re-frame Rum Om
re-natal
Try CLJS withTry CLJS with LumoLumo
$ npm install -g lumo-cljs
$ lumo
cljs.user=> (defn hello [& {:keys [to]
#_=> :or {to "world"}}]
#_=> (println (str "Hello, " to "!")))
#'cljs.user/hello
cljs.user=> (hello)
Hello, world!
nil
cljs.user=> (hello :to "ClojureScript")
Hello, ClojureScript!
nil
Good PartsGood Parts
LispLisp
S-expressions (sexp)S-expressions (sexp)
simple rule: (op arg ...)
various kinds of
functions
macros
special forms
structural editing
, , etc.ParEdit Parinfer
Collection LiteralsCollection Literals
cf. function de nition
cljs.user=> '(1 2 3) ; list
(1 2 3)
cljs.user=> [1 2 3] ; vector
[1 2 3]
cljs.user=> #{1 2 3} ; set
#{1 2 3}
cljs.user=> {:a 1 :b 2 :c 3} ; map
{:a 1, :b 2, :c 3}
(defn hello [& {:keys [to]
:or {to "world"}}]
(println (str "Hello, " to "!")))
Lisp MacrosLisp Macros
compile-time metaprogramming
code as data
sexp -> sexp
e.g. for macro (sequence comprehension)
;; ClojureScript
cljs.user=> (for [x (range 10)
#_=> :when (odd? x)]
#_=> (* x x))
(1 9 25 49 81)
cljs.user=> (macroexpand-1
#_=> '(for [x (range 10)
#_=> :when (odd? x)]
#_=> (* x x)))
(cljs.core$macros/let
[iter__9116__auto__
(cljs.core$macros/fn
,,,
# Python
>>> [x ** 2 for x in range(10) if x % 2 != 0]
[1, 9, 25, 49, 81]
-- Haskell
> [x ^ 2 | x <- [0..9], odd x]
[1,9,25,49,81]
REPL-driven DevelopmentREPL-driven Development
Create a ClojureScript project with Leiningen
$ brew install leiningen
$ lein new figwheel cljs-demo # e.g. "figwheel" template
$ cd cljs-demo
$ lein figwheel # or `cider-jack-in-clojurescript` on Emacs
editor-integrated REPL (e.g. Emacs & )CIDER
browser REPL for front-end development
Changes are automatically loaded in the browser
FunctionalFunctional
ProgrammingProgramming
Immutable PersistentImmutable Persistent
CollectionsCollections
no mutations, no side e ects
high performance
ljs.user=> (conj [1 2] 3) ; add an element to vector
[1 2 3]
cljs.user=> (conj '(1 2) 3) ; add an element to list
(3 1 2)
cljs.user=> (conj #{1 2} 3) ; add an element to set
#{1 2 3}
cljs.user=> (assoc {:a 1 :b 2} :c 3) ; add an entry to map
{:a 1, :b 2, :c 3}
Map and SequenceMap and Sequence
as Core Abstractionsas Core Abstractions
maps: get, assoc
sequences: first, rest, cons
lazy sequences
rare to de ne something like classes or algebraic
data types
few data abstractions and many functions
e.g. maps for modelling entities
cljs.user=> (ns geometry.sphere)
nil
geometry.sphere=> (defn surface-area [{::keys [radius]}]
#_=> (* 4 Math/PI (Math/pow radius 2)))
#'geometry.sphere/surface-area
geometry.sphere=> (defn volume [{::keys [radius]}]
#_=> (* 4/3 Math/PI (Math/pow radius 3)))
#'geometry.sphere/volume
geometry.sphere=> #::{:radius 2}
#:geometry.sphere{:radius 2}
geometry.sphere=> (surface-area #::{:radius 2})
50.26548245743669
geometry.sphere=> (volume #::{:radius 2})
33.510321638291124
e.g. typical sequence manipulations
cljs.user=> (defn leibniz [n-terms]
#_=> (->> (iterate #(+ % 2) 1)
#_=> (map / (cycle [1 -1]))
#_=> (take n-terms)
#_=> (apply +)
#_=> (* 4.0)))
#'cljs.user/leibniz
cljs.user=> (leibniz 1000)
3.140592653839794
cljs.user=> (leibniz 10000)
3.1414926535900345
cljs.user=> (leibniz 100000)
3.1415826535897198
Data > Functions > MacrosData > Functions > Macros
data-driven/oriented design
examples
libraries: , ,
frameworks: , ,
Honey SQL Hiccup Reagent
Duct Pedestal re-frame
speci cation system
similar to Racket's
cf. gradual typing
e.g. (Typed Clojure)
clojure.specclojure.spec
contract system
core.typed
Common mistakes with maps ...
;; typo in key name
geometry.sphere=> (surface-area #::{:radias 2})
0
;; incorrect value type
geometry.sphere=> (volume #::{:radius "2"})
33.510321638291124
Introduce clojure.spec
geometry.sphere=> (require '[cljs.spec.alpha :as s
#_=> :include-macros true])
nil
geometry.sphere=> (s/def ::radius (s/and number? pos?))
:geometry.sphere/radius
geometry.sphere=> (s/def ::sphere (s/keys :req [::radius]))
:geometry.sphere/sphere
geometry.sphere=> (s/fdef surface-area
#_=> :args (s/cat :sphere ::sphere)
#_=> :ret number?)
geometry.sphere/surface-area
geometry.sphere=> (s/fdef volume
#_=> :args (s/cat :sphere ::sphere)
#_=> :ret number?)
geometry.sphere/volume
Instrument specs
※ add as a dependency (cf. )
geometry.sphere=> (require '[cljs.spec.test.alpha :as stest
#_=> :include-macros true])
nil
geometry.sphere=> (stest/instrument)
[geometry.sphere/surface-area geometry.sphere/volume]
test.check CLJS-1792
# for example
$ lumo -c src:~/.m2/repository/org/clojure/test.check-0.9.0.jar
Spec-instrumented surface­area function
geometry.sphere=> (surface-area #::{:radius 2})
50.26548245743669
geometry.sphere=> (surface-area #::{:radias 2})
Call to #'geometry.sphere/surface-area did not conform to spec:
In: [0] val: #:geometry.sphere{:radias 2} fails
spec: :geometry.sphere/sphere
at: [:args :sphere]
predicate: (contains? % :geometry.sphere/radius)
:cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha
10508]
:cljs.spec.alpha/value (#:geometry.sphere{:radias 2})
:cljs.spec.alpha/args (#:geometry.sphere{:radias 2})
:cljs.spec.alpha/failure :instrument
,,,
Spec-instrumented volume function
geometry.sphere=> (volume #::{:radius 2})
33.510321638291124
geometry.sphere=> (volume #::{:radius "2"})
Call to #'geometry.sphere/volume did not conform to spec:
In: [0 :geometry.sphere/radius] val: "2" fails
spec: :geometry.sphere/radius
at: [:args :sphere :geometry.sphere/radius]
predicate: number?
:cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha
10508]
:cljs.spec.alpha/value (#:geometry.sphere{:radius "2"})
:cljs.spec.alpha/args (#:geometry.sphere{:radius "2"})
:cljs.spec.alpha/failure :instrument
,,,
Land of Lisp invades JS world!!Land of Lisp invades JS world!!
Further ReadingFurther Reading
ClojureClojure
Clojure o cial site
日本語版
Clojureの世界と実際のWeb開発
Clojureの世界観
ClojureでREPL駆動開発を始めよう
Spectacular Future with clojure.spec
ClojureScriptClojureScript
ClojureScript o cial site
Reagent/re-frameReagent/re-frame
cf.
Reagent
Guide to Reagent
re-frame
Re-frame: The Guide to Building Blocks
ClojureScript & ReagentでReact入門してみた
ClojureScript/re-frame開発における思考フロー
Elm開発における思考フロー

Mais conteúdo relacionado

Mais procurados

JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
Solution4Future
 

Mais procurados (20)

JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
node ffi
node ffinode ffi
node ffi
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy
 
用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
High Performance tDiary
High Performance tDiaryHigh Performance tDiary
High Performance tDiary
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder Ruby
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
From Java To Clojure (English version)
From Java To Clojure (English version)From Java To Clojure (English version)
From Java To Clojure (English version)
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 

Semelhante a ClojureScript: The Good Parts

Samsung WebCL Prototype API
Samsung WebCL Prototype APISamsung WebCL Prototype API
Samsung WebCL Prototype API
Ryo Jin
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
Raimonds Simanovskis
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
elliando dias
 
Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrāde
Raimonds Simanovskis
 

Semelhante a ClojureScript: The Good Parts (20)

Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
It's Time to Get Ready for the Power of PL/SQL and JavaScript Combined
It's Time to Get Ready for the Power  of PL/SQL and JavaScript CombinedIt's Time to Get Ready for the Power  of PL/SQL and JavaScript Combined
It's Time to Get Ready for the Power of PL/SQL and JavaScript Combined
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Samsung WebCL Prototype API
Samsung WebCL Prototype APISamsung WebCL Prototype API
Samsung WebCL Prototype API
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.js
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJS
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixir
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
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
 
The Unicorn Getting Interested in KDE
The Unicorn Getting Interested in KDEThe Unicorn Getting Interested in KDE
The Unicorn Getting Interested in KDE
 
Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrāde
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 

Mais de Kent Ohashi

Mais de Kent Ohashi (20)

インターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPC
インターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPCインターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPC
インターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPC
 
Team Geek Revisited
Team Geek RevisitedTeam Geek Revisited
Team Geek Revisited
 
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt TechnologiesScala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
 
Clojureコレクションで探るimmutableでpersistentな世界
Clojureコレクションで探るimmutableでpersistentな世界Clojureコレクションで探るimmutableでpersistentな世界
Clojureコレクションで探るimmutableでpersistentな世界
 
英語学習者のためのフランス語文法入門: フランス語完全理解(?)
英語学習者のためのフランス語文法入門: フランス語完全理解(?)英語学習者のためのフランス語文法入門: フランス語完全理解(?)
英語学習者のためのフランス語文法入門: フランス語完全理解(?)
 
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミングJavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
 
実用のための語源学入門
実用のための語源学入門実用のための語源学入門
実用のための語源学入門
 
メタプログラミング入門
メタプログラミング入門メタプログラミング入門
メタプログラミング入門
 
労働法の世界
労働法の世界労働法の世界
労働法の世界
 
Clojureで作る"simple"なDSL
Clojureで作る"simple"なDSLClojureで作る"simple"なDSL
Clojureで作る"simple"なDSL
 
RDBでのツリー表現入門
RDBでのツリー表現入門RDBでのツリー表現入門
RDBでのツリー表現入門
 
GraphQL入門
GraphQL入門GraphQL入門
GraphQL入門
 
Everyday Life with clojure.spec
Everyday Life with clojure.specEveryday Life with clojure.spec
Everyday Life with clojure.spec
 
たのしい多言語学習
たのしい多言語学習たのしい多言語学習
たのしい多言語学習
 
Ductモジュール入門
Ductモジュール入門Ductモジュール入門
Ductモジュール入門
 
Clojure REPL: The Good Parts
Clojure REPL: The Good PartsClojure REPL: The Good Parts
Clojure REPL: The Good Parts
 
GraphQL API in Clojure
GraphQL API in ClojureGraphQL API in Clojure
GraphQL API in Clojure
 
法学入門
法学入門法学入門
法学入門
 
Boost your productivity with Clojure REPL
Boost your productivity with Clojure REPLBoost your productivity with Clojure REPL
Boost your productivity with Clojure REPL
 
Clojure Linters
Clojure LintersClojure Linters
Clojure Linters
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Último (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 

ClojureScript: The Good Parts

  • 2. カマイルカ /laʒenɔʁɛ̃k/カマイルカ /laʒenɔʁɛ̃k/ lagénorhynquelagénorhynque (defprofile lagénorhynque :name "Kent OHASHI" :languages [Clojure Haskell Python Scala English français Deutsch русский] :interests [programming language-learning mathematics] :contributing [github.com/japan-clojurians/clojure-site-ja])
  • 3. Lisp × JavaScriptLisp × JavaScript
  • 4. What is ClojureScript?What is ClojureScript?
  • 5. (CLJS)(CLJS) compiler for Clojure that targets JavaScript cf. (JVM/Java), (CLR/C#) simple and powerful functional Lisp ClojureScriptClojureScript Clojure ClojureCLR
  • 6. Use CasesUse Cases SPA: / , , , etc. React Native: Electron Node.js AWS Lambda etc. Reagent re-frame Rum Om re-natal
  • 7. Try CLJS withTry CLJS with LumoLumo $ npm install -g lumo-cljs $ lumo cljs.user=> (defn hello [& {:keys [to] #_=> :or {to "world"}}] #_=> (println (str "Hello, " to "!"))) #'cljs.user/hello cljs.user=> (hello) Hello, world! nil cljs.user=> (hello :to "ClojureScript") Hello, ClojureScript! nil
  • 10. S-expressions (sexp)S-expressions (sexp) simple rule: (op arg ...) various kinds of functions macros special forms structural editing , , etc.ParEdit Parinfer
  • 11. Collection LiteralsCollection Literals cf. function de nition cljs.user=> '(1 2 3) ; list (1 2 3) cljs.user=> [1 2 3] ; vector [1 2 3] cljs.user=> #{1 2 3} ; set #{1 2 3} cljs.user=> {:a 1 :b 2 :c 3} ; map {:a 1, :b 2, :c 3} (defn hello [& {:keys [to] :or {to "world"}}] (println (str "Hello, " to "!")))
  • 12. Lisp MacrosLisp Macros compile-time metaprogramming code as data sexp -> sexp
  • 13. e.g. for macro (sequence comprehension) ;; ClojureScript cljs.user=> (for [x (range 10) #_=> :when (odd? x)] #_=> (* x x)) (1 9 25 49 81) cljs.user=> (macroexpand-1 #_=> '(for [x (range 10) #_=> :when (odd? x)] #_=> (* x x))) (cljs.core$macros/let [iter__9116__auto__ (cljs.core$macros/fn ,,, # Python >>> [x ** 2 for x in range(10) if x % 2 != 0] [1, 9, 25, 49, 81] -- Haskell > [x ^ 2 | x <- [0..9], odd x] [1,9,25,49,81]
  • 14. REPL-driven DevelopmentREPL-driven Development Create a ClojureScript project with Leiningen $ brew install leiningen $ lein new figwheel cljs-demo # e.g. "figwheel" template $ cd cljs-demo $ lein figwheel # or `cider-jack-in-clojurescript` on Emacs
  • 16.
  • 17. browser REPL for front-end development
  • 18. Changes are automatically loaded in the browser
  • 20. Immutable PersistentImmutable Persistent CollectionsCollections no mutations, no side e ects high performance ljs.user=> (conj [1 2] 3) ; add an element to vector [1 2 3] cljs.user=> (conj '(1 2) 3) ; add an element to list (3 1 2) cljs.user=> (conj #{1 2} 3) ; add an element to set #{1 2 3} cljs.user=> (assoc {:a 1 :b 2} :c 3) ; add an entry to map {:a 1, :b 2, :c 3}
  • 21. Map and SequenceMap and Sequence as Core Abstractionsas Core Abstractions maps: get, assoc sequences: first, rest, cons lazy sequences rare to de ne something like classes or algebraic data types few data abstractions and many functions
  • 22. e.g. maps for modelling entities cljs.user=> (ns geometry.sphere) nil geometry.sphere=> (defn surface-area [{::keys [radius]}] #_=> (* 4 Math/PI (Math/pow radius 2))) #'geometry.sphere/surface-area geometry.sphere=> (defn volume [{::keys [radius]}] #_=> (* 4/3 Math/PI (Math/pow radius 3))) #'geometry.sphere/volume geometry.sphere=> #::{:radius 2} #:geometry.sphere{:radius 2} geometry.sphere=> (surface-area #::{:radius 2}) 50.26548245743669 geometry.sphere=> (volume #::{:radius 2}) 33.510321638291124
  • 23. e.g. typical sequence manipulations cljs.user=> (defn leibniz [n-terms] #_=> (->> (iterate #(+ % 2) 1) #_=> (map / (cycle [1 -1])) #_=> (take n-terms) #_=> (apply +) #_=> (* 4.0))) #'cljs.user/leibniz cljs.user=> (leibniz 1000) 3.140592653839794 cljs.user=> (leibniz 10000) 3.1414926535900345 cljs.user=> (leibniz 100000) 3.1415826535897198
  • 24. Data > Functions > MacrosData > Functions > Macros data-driven/oriented design examples libraries: , , frameworks: , , Honey SQL Hiccup Reagent Duct Pedestal re-frame
  • 25. speci cation system similar to Racket's cf. gradual typing e.g. (Typed Clojure) clojure.specclojure.spec contract system core.typed
  • 26. Common mistakes with maps ... ;; typo in key name geometry.sphere=> (surface-area #::{:radias 2}) 0 ;; incorrect value type geometry.sphere=> (volume #::{:radius "2"}) 33.510321638291124
  • 27. Introduce clojure.spec geometry.sphere=> (require '[cljs.spec.alpha :as s #_=> :include-macros true]) nil geometry.sphere=> (s/def ::radius (s/and number? pos?)) :geometry.sphere/radius geometry.sphere=> (s/def ::sphere (s/keys :req [::radius])) :geometry.sphere/sphere geometry.sphere=> (s/fdef surface-area #_=> :args (s/cat :sphere ::sphere) #_=> :ret number?) geometry.sphere/surface-area geometry.sphere=> (s/fdef volume #_=> :args (s/cat :sphere ::sphere) #_=> :ret number?) geometry.sphere/volume
  • 28. Instrument specs ※ add as a dependency (cf. ) geometry.sphere=> (require '[cljs.spec.test.alpha :as stest #_=> :include-macros true]) nil geometry.sphere=> (stest/instrument) [geometry.sphere/surface-area geometry.sphere/volume] test.check CLJS-1792 # for example $ lumo -c src:~/.m2/repository/org/clojure/test.check-0.9.0.jar
  • 29. Spec-instrumented surface­area function geometry.sphere=> (surface-area #::{:radius 2}) 50.26548245743669 geometry.sphere=> (surface-area #::{:radias 2}) Call to #'geometry.sphere/surface-area did not conform to spec: In: [0] val: #:geometry.sphere{:radias 2} fails spec: :geometry.sphere/sphere at: [:args :sphere] predicate: (contains? % :geometry.sphere/radius) :cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha 10508] :cljs.spec.alpha/value (#:geometry.sphere{:radias 2}) :cljs.spec.alpha/args (#:geometry.sphere{:radias 2}) :cljs.spec.alpha/failure :instrument ,,,
  • 30. Spec-instrumented volume function geometry.sphere=> (volume #::{:radius 2}) 33.510321638291124 geometry.sphere=> (volume #::{:radius "2"}) Call to #'geometry.sphere/volume did not conform to spec: In: [0 :geometry.sphere/radius] val: "2" fails spec: :geometry.sphere/radius at: [:args :sphere :geometry.sphere/radius] predicate: number? :cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha 10508] :cljs.spec.alpha/value (#:geometry.sphere{:radius "2"}) :cljs.spec.alpha/args (#:geometry.sphere{:radius "2"}) :cljs.spec.alpha/failure :instrument ,,,
  • 31. Land of Lisp invades JS world!!Land of Lisp invades JS world!!
  • 33. ClojureClojure Clojure o cial site 日本語版 Clojureの世界と実際のWeb開発 Clojureの世界観 ClojureでREPL駆動開発を始めよう Spectacular Future with clojure.spec
  • 35. Reagent/re-frameReagent/re-frame cf. Reagent Guide to Reagent re-frame Re-frame: The Guide to Building Blocks ClojureScript & ReagentでReact入門してみた ClojureScript/re-frame開発における思考フロー Elm開発における思考フロー