SlideShare a Scribd company logo
1 of 30
Download to read offline
Julia is your friend
fu7mu4@関西Lispユーザー会
fu7mu4
• 主に関西Lispユーザー会と姫路IT系勉強会に参加
• 「Eclipseはじめました」ネタでEclipse Lisp※を紹介し
た。ごめんなさい
• ※IDEとは関係ない
1.0.1 is released !
Julia
• https://julialang.org/
• https://github.com/JuliaLang/julia
• MIT License
“Why we created Julia ?”
says
• まず、ゆるいライセンスのオープンソースで、Cの速度と
Rubyの動的さが欲しい。Lispのような真のマクロが使え
る同図象性のある言語で、Matlabのように分かりやすい
数学の記述をしたい。Pythonのように汎用的に使いたい
し、Rの統計処理、Perlの文字列処理、Matlabの線形代
数計算も要る。シェルのように簡単にいくつかのパーツを
つなぎ合わせたい。チョー簡単に習えて、超上級ハッカー
も満足する言語。インタラクティブに使えて、かつコンパ
イルできる言語が欲しい。
“Why we created Julia ?”
says
• まず、ゆるいライセンスのオープンソースで、Cの速度と
Rubyの動的さが欲しい。Lispのような真のマクロが使え
る同図象性のある言語で、Matlabのように分かりやすい
数学の記述をしたい。Pythonのように汎用的に使いたい
し、Rの統計処理、Perlの文字列処理、Matlabの線形代
数計算も要る。シェルのように簡単にいくつかのパーツを
つなぎ合わせたい。チョー簡単に習えて、超上級ハッカー
も満足する言語。インタラクティブに使えて、かつコンパ
イルできる言語が欲しい。
“Why we created Julia ?”
says
• まず、ゆるいライセンスのオープンソースで、Cの速度と
Rubyの動的さが欲しい。Lispのような真のマクロが使え
る同図象性のある言語で、Matlabのように分かりやすい
数学の記述をしたい。Pythonのように汎用的に使いたい
し、Rの統計処理、Perlの文字列処理、Matlabの線形代
数計算も要る。シェルのように簡単にいくつかのパーツを
つなぎ合わせたい。チョー簡単に習えて、超上級ハッカー
も満足する言語。インタラクティブに使えて、かつコンパ
イルできる言語が欲しい。
Common Lisp使ったら?
Julia is popular
by google trends
Julia is popular
fibo in julia & C
function fibo(n)
if n < 2
return n
else
return fibo(n - 1) + fibo(n - 2)
end
end
long long fibo(long long n){
if (n < 2) {
return n;
} else {
return fibo(n - 1) + fibo(n - 2);
}
}
型推論+LLVM JITコンパイラ
スクリプト
静的に型を宣言+GCC
コンパイル
fibo in cl/scheme
(defun fibo(n)
(if (< 2 n)
n
(+ (fibo (- n 1) (fibo (- n 2))))
(define (fibo n)
(if (< 2 n)
n
(+ (fibo (- n 1)) (fibo (- n 2)))))
sbcl (common lisp)
コンパイル
chez scheme (scheme)
+ JIT コンパイラ
speed of fibo(50)
compiler/interpreter seconds
gcc with -O3 [v6.3] 39.317
gcc with -O2 [v6.3] 46.095
julia [v1.0.1] 60.066
gcc with -O0 [v6.3] 77.021
chez scheme [v9.5] 111.660
sbcl [v1.3.14] 252.521
Julia is your friends
Julia is your friend(Demo)
• Just run on Julia with special option
Julia
julia interactive mode
Femtolisp
julia with ̶lisp option
Femtolisp
• https://github.com/JeffBezanson/femtolisp
• Lisp-1 (Scheme ?)
• 小さくて、単純で、埋め込みしやすい
• Julia の内部で パーサーとして使用
• 作者がJuliaの原作者の一人
• 問題があればすぐに修正される
の話でしたね
Julia is your friend
• インタプリタ、コンパイルあり
• レキシカルスコープ
• 型宣言はなくてもよいが、型宣言もできる
• 値に型がある、変数にはない
• 関数は First Classオブジェクト
• CLOSライクなメソッド(generic function)
シンボル
julia> :foo
:foo
julia> typeof(ans)
Symbol
julia> :foo == Symbol(“foo”)
true
文字列とパース
julia> prog = "1 + 1"
"1 + 1"
julia> ex1 = Meta.parse(prog)
:(1 + 1)
julia> ex2 = Expr(:call, :+, 1, 1)
:(1 + 1)
パースとS式
julia> ex3 = Meta.parse("(4 + 4) / 2")
:((4 + 4) / 2)
julia> Meta.show_sexpr(ex3)
(:call, :/, (:call, :+, 4, 4), 2)
`(,a b)
julia> a = 1;
julia> ex = :($a + b)
:(1 + b)
julia> ex = :(a in $:((1,2,3)) )
:(a in (1, 2, 3))
(eval ``(,x))
julia> x = :(1 + 2);
julia> e = quote quote $x end end
quote
#= none:1 =#
$(Expr(:quote, quote
#= none:1 =#
$(Expr(:$, :x))
end))
end
julia> eval(e)
quote
#= none:1 =#
1 + 2
end
Exprを返す関数
julia> function math_expr(op, op1, op2)
expr = Expr(:call, op, op1, op2)
return expr
end
math_expr (generic function with 1method)
julia> ex = math_expr(:+, 1, Expr(:call, :*, 4, 5))
:( 1 + 4 * 5)
julia> eval(ex)
21
マクロ
julia> macro sayhello (name)
return :( println(“Hello ”, $name))
end
@sayhello (macro with 1 method)
julia> @sayhello(“関西Lispユーザー会”)
“Hello 関西Lispユーザー会”
マクロディスパッチ
julia> macro sayhello ()
return :( println(“Hello , Everyone”))
end
@sayhello (macro with 1 method)
JuliaではCLOSのメソッドと同じで
同名で引数が異なるマクロを定義できる
macroexpandマクロ
julia> @macroexpand @sayhello “name”
:((println)(“Hello “, “name”)
名前衝突もある
• Common Lispのマクロ
• Schemeでいう伝統的マクロ
• 名前の衝突を回避する必要がある
• 新しいシンボルをローカルにする
• 新しいグローバルシンボルはgensym関数で生成
まとめ
• Julia ユーザーは Lispユーザー(Femtolisp使ってる)
• Julia は J式
• Julia is your friend (=LisperはJuliaをすぐ使える)

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Julia is your friend (Japanese)

  • 1. Julia is your friend fu7mu4@関西Lispユーザー会
  • 5. “Why we created Julia ?” says • まず、ゆるいライセンスのオープンソースで、Cの速度と Rubyの動的さが欲しい。Lispのような真のマクロが使え る同図象性のある言語で、Matlabのように分かりやすい 数学の記述をしたい。Pythonのように汎用的に使いたい し、Rの統計処理、Perlの文字列処理、Matlabの線形代 数計算も要る。シェルのように簡単にいくつかのパーツを つなぎ合わせたい。チョー簡単に習えて、超上級ハッカー も満足する言語。インタラクティブに使えて、かつコンパ イルできる言語が欲しい。
  • 6. “Why we created Julia ?” says • まず、ゆるいライセンスのオープンソースで、Cの速度と Rubyの動的さが欲しい。Lispのような真のマクロが使え る同図象性のある言語で、Matlabのように分かりやすい 数学の記述をしたい。Pythonのように汎用的に使いたい し、Rの統計処理、Perlの文字列処理、Matlabの線形代 数計算も要る。シェルのように簡単にいくつかのパーツを つなぎ合わせたい。チョー簡単に習えて、超上級ハッカー も満足する言語。インタラクティブに使えて、かつコンパ イルできる言語が欲しい。
  • 7. “Why we created Julia ?” says • まず、ゆるいライセンスのオープンソースで、Cの速度と Rubyの動的さが欲しい。Lispのような真のマクロが使え る同図象性のある言語で、Matlabのように分かりやすい 数学の記述をしたい。Pythonのように汎用的に使いたい し、Rの統計処理、Perlの文字列処理、Matlabの線形代 数計算も要る。シェルのように簡単にいくつかのパーツを つなぎ合わせたい。チョー簡単に習えて、超上級ハッカー も満足する言語。インタラクティブに使えて、かつコンパ イルできる言語が欲しい。 Common Lisp使ったら?
  • 8. Julia is popular by google trends
  • 10. fibo in julia & C function fibo(n) if n < 2 return n else return fibo(n - 1) + fibo(n - 2) end end long long fibo(long long n){ if (n < 2) { return n; } else { return fibo(n - 1) + fibo(n - 2); } } 型推論+LLVM JITコンパイラ スクリプト 静的に型を宣言+GCC コンパイル
  • 11. fibo in cl/scheme (defun fibo(n) (if (< 2 n) n (+ (fibo (- n 1) (fibo (- n 2)))) (define (fibo n) (if (< 2 n) n (+ (fibo (- n 1)) (fibo (- n 2))))) sbcl (common lisp) コンパイル chez scheme (scheme) + JIT コンパイラ
  • 12. speed of fibo(50) compiler/interpreter seconds gcc with -O3 [v6.3] 39.317 gcc with -O2 [v6.3] 46.095 julia [v1.0.1] 60.066 gcc with -O0 [v6.3] 77.021 chez scheme [v9.5] 111.660 sbcl [v1.3.14] 252.521
  • 13. Julia is your friends
  • 14. Julia is your friend(Demo) • Just run on Julia with special option
  • 17. Femtolisp • https://github.com/JeffBezanson/femtolisp • Lisp-1 (Scheme ?) • 小さくて、単純で、埋め込みしやすい • Julia の内部で パーサーとして使用 • 作者がJuliaの原作者の一人 • 問題があればすぐに修正される
  • 19. Julia is your friend • インタプリタ、コンパイルあり • レキシカルスコープ • 型宣言はなくてもよいが、型宣言もできる • 値に型がある、変数にはない • 関数は First Classオブジェクト • CLOSライクなメソッド(generic function)
  • 21. 文字列とパース julia> prog = "1 + 1" "1 + 1" julia> ex1 = Meta.parse(prog) :(1 + 1) julia> ex2 = Expr(:call, :+, 1, 1) :(1 + 1)
  • 22. パースとS式 julia> ex3 = Meta.parse("(4 + 4) / 2") :((4 + 4) / 2) julia> Meta.show_sexpr(ex3) (:call, :/, (:call, :+, 4, 4), 2)
  • 23. `(,a b) julia> a = 1; julia> ex = :($a + b) :(1 + b) julia> ex = :(a in $:((1,2,3)) ) :(a in (1, 2, 3))
  • 24. (eval ``(,x)) julia> x = :(1 + 2); julia> e = quote quote $x end end quote #= none:1 =# $(Expr(:quote, quote #= none:1 =# $(Expr(:$, :x)) end)) end julia> eval(e) quote #= none:1 =# 1 + 2 end
  • 25. Exprを返す関数 julia> function math_expr(op, op1, op2) expr = Expr(:call, op, op1, op2) return expr end math_expr (generic function with 1method) julia> ex = math_expr(:+, 1, Expr(:call, :*, 4, 5)) :( 1 + 4 * 5) julia> eval(ex) 21
  • 26. マクロ julia> macro sayhello (name) return :( println(“Hello ”, $name)) end @sayhello (macro with 1 method) julia> @sayhello(“関西Lispユーザー会”) “Hello 関西Lispユーザー会”
  • 27. マクロディスパッチ julia> macro sayhello () return :( println(“Hello , Everyone”)) end @sayhello (macro with 1 method) JuliaではCLOSのメソッドと同じで 同名で引数が異なるマクロを定義できる
  • 28. macroexpandマクロ julia> @macroexpand @sayhello “name” :((println)(“Hello “, “name”)
  • 29. 名前衝突もある • Common Lispのマクロ • Schemeでいう伝統的マクロ • 名前の衝突を回避する必要がある • 新しいシンボルをローカルにする • 新しいグローバルシンボルはgensym関数で生成
  • 30. まとめ • Julia ユーザーは Lispユーザー(Femtolisp使ってる) • Julia は J式 • Julia is your friend (=LisperはJuliaをすぐ使える)