SlideShare a Scribd company logo
1 of 11
Download to read offline
clojureでAndroid
   @Geekbar
        2012/10/22
 (2012/10/26 公開用に修正)

       櫻井 雄大
     (@Y_Sakurai)
なんでまたclojure?
         Android開発やることになった
                     ↓
                Javaは面倒だ
                     ↓
      最近、関数型というのがトレンドらしい
                     ↓
    せっかくだから、俺は新しい言語を学ぶぜ!
                     ↓
    Androidで動く関数型言語はいねぇがー!
                     ↓
              せいかい:clojure
そもそもclojureてなんやねん
(以下、大体書籍のパクリ引用および勝手な解釈)
・Lisp リローデッド
(ほぼLisp。数ある方言の一つぐらいのノリ)
・関数型だけど若干ゆるふわ
(ある程度手続きを踏めば、副作用を許す)
・JVMで動く
・末尾再帰などの最適化は苦手
(スタックオーバーフローとかあるので、再帰は慎重に)
・オンメモリトランザクションとか並行処理的なアレ
・Javaを許容する
(必要があれば、いつでもJavaのクラス/オブジェクトに"容易に"アクセスできる)
・REPL(Read-Eval-Print-Loop)が便利
その場で書いて即実行!
clojure on Android 情報
~2008年ごろ?
android-swank-clojureのスライドがTakumi KINJO氏により公開される
http://kinjo.github.com/ojag-clojure/#slide1
githubにコードが公開され、動作事例やemacsでの開発環境構築手順がWeb上に出
回る

~2010年ごろ
なんかgithubのandroid-swank-clojureリポジトリが消される。他の情報も途絶える

~2011年から現在
ひっそりとclojure用フレームワークなどが現れる(後述)
誰も気づいてないっぽいがどうなのか
leiningen
leiningen - clojureプロジェクト管理ツール
https://github.com/technomancy/leiningen#readme

Javaな人は、
「AntとMavenと他色々便利なものがセットになった
よ的なもの」ぐらいの認識でおk
bashスクリプトをwgetして実行するだけで簡単導
入!
clojureそのものもインストールしてくれるので、とっ
てもお手軽
neko
https://github.com/alexander-yakushev/neko

androidアプリをclojureで開発するために便利なフ
レームワーク
ベースはsattvikさん、今はalexander-yakushevさん
のforkが開発進行中
lein-droid
https://github.com/alexander-yakushev/lein-droid

leiningenのプラグイン的なもの
プロジェクトの作成、ビルド、インストール、REPLの
起動まで一手に担う頑張り屋

debugビルドで、自動的にREPLサーバをアプリに
組み込む
→REPLで直接起動中のアプリをいじれる!
実際に試してみた

実際に接続してUIを直接書き換える例:
#--- サンプルプロジェクトの作成(neko-sampleディレクトリにパッケージ名com.example.nekosampleでプロジェクトを作成)
$ lein new neko-sample com.example.nekosample


#--- ビルド,apk作成,インストール,実行,localhost:9999を接続済実機orエミュ:9999にフォワード
$ cd neko-sample && lein do droid build, droid apk, droid deploy


#--- アプリが立ち上がったら、replを接続先指定して接続
$ lein repl :connect localhost:9999
(起動メッセージ省略)
user=> (ns com.example.nekosample.main
 (:use [neko.activity]
     [neko.threading]
     [neko.ui]
     [neko.application]
     [neko.find-view]))
com.example.sampleapp.main=> (on-ui (set-content-view! a (make-ui [:linear-layout {} [:text-view {:text "Hello from REPL!"}]]))) ; ビューを新規作
成して置換する
clojureでのAndroid開発雑感
・replが使える
なんといっても、repl(Read-Eval-Print-Loop)が凶悪に便利。
エミュ/実機上でコード書いてEval>動作確認取ってからプログ
ラムファイルに書き出す、という流れが素晴らしい。
新時代の開発フローの幕開けや!

・leiningenが使える
clojureのプロジェクト管理ツールのleiningenが良い。
jarライブラリの依存関係もproject.cljに1行追記するだけ。

・記述量が少ない
延々と身のないimplementsを書く苦痛から開放される。
関数型言語+コンパイラ性能のおかげでウッカリミスもかなり少ない。
clojureでのAndroid開発雑感
・Lisp文法のとっつきにくさ
実際学習してみるとそれほど難しくないのだが、知らない人にとっては暗号レベル。
LISPを使ったことある人なら話は別。

・アプリのブートが遅い
軽く2~30秒ぐらいかかる。
回避策というか、通常のJavaで起動画面を出すことで、ユーザの不安を解消するのは必要だと思う。

・ノウハウがない
clojureがいつのまにか1.4.0で、既存の日本語文献にあるような解説はアテにならない。contrib消えてるし...
今のところ唯一のclojure用Androidフレームワークであるnekoも、若いしコミュニティも小さく、ドキュメントも
APIレベルでの記載しかない。
「使い方知りたかったらソース見ろや」という漢らしいスタイル。
日本語文献とかほぼ0。ちょっと怖い。
see also...
● clojars
https://clojars.org/
https://github.com/ato/clojars-web
clojure向けライブラリが登録されているリポジトリ。サイトそのものがclojureで記述されており、ソースコード
も公開されているので、clojureでWebアプリ開発をしたい人にもオススメ。
ちなみに、leiningenを使ってclojarsにオレオレライブラリを簡単に公開できるよ!こんな感じ↓
https://clojars.org/show-reflect

● プログラミングclojure
http://www.amazon.co.jp/%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%
83%B3%E3%82%B0Clojure-Stuart-Halloway/dp/4274067890/ref=sr_1_1?
ie=UTF8&qid=1351190794&sr=8-1
現状、(多分)唯一のclojure日本語書籍。内容はver1.1あたりがベースなので、一部のコードは(contribライブ
ラリ移転等の影響で)動作しない。その辺も含めて、勉強がてら自分で試行錯誤してみると楽しい。ちなみに
contribの詳細は以下参照のこと。
http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go

More Related Content

Recently uploaded

Recently uploaded (11)

知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 

Featured

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
ThinkNow
 
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
Kurio // The Social Media Age(ncy)
 

Featured (20)

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...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

【公開版】Clojureでandroid開発@geekbar