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

研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
atsushi061452
 

Recently uploaded (12)

Intranet Development v1.0 (TSG LIVE! 12 LT )
Intranet Development v1.0 (TSG LIVE! 12 LT )Intranet Development v1.0 (TSG LIVE! 12 LT )
Intranet Development v1.0 (TSG LIVE! 12 LT )
 
LoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアル
LoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアルLoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアル
LoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアル
 
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
 
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
 
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
 
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
 
情報を表現するときのポイント
情報を表現するときのポイント情報を表現するときのポイント
情報を表現するときのポイント
 
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイルLoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
 
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
 
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdfネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
 
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
 
Keywordmap overview material/CINC.co.ltd
Keywordmap overview material/CINC.co.ltdKeywordmap overview material/CINC.co.ltd
Keywordmap overview material/CINC.co.ltd
 

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